Skip to content

feat: implement graceful shutdown for all tarpit servers#14

Open
vinayaktyagi10 wants to merge 2 commits intohoneynet:mainfrom
vinayaktyagi10:feat/graceful-shutdown
Open

feat: implement graceful shutdown for all tarpit servers#14
vinayaktyagi10 wants to merge 2 commits intohoneynet:mainfrom
vinayaktyagi10:feat/graceful-shutdown

Conversation

@vinayaktyagi10
Copy link
Copy Markdown

Summary

Implements graceful shutdown handling across all four tarpit servers
(telnet, upnp, coap, mqtt).

Changes

  • Add SIGINT/SIGTERM signal handlers using sig_atomic_t flag
  • Replace while(1) with while(keepRunning) in all four pits
  • Drain client queues on shutdown, emitting disconnect metrics for
    each active client so Prometheus receives accurate final data
  • Fix poll/epoll_wait to use bounded timeouts (1000ms) so signal
    delivery isn't blocked indefinitely on an empty queue
  • Handle EINTR in poll, epoll_wait, and recvfrom error paths

Why

Without graceful shutdown, active clients are dropped silently on
SIGINT/SIGTERM (e.g. container restarts), causing the Prometheus
exporter to never receive their disconnect events. This leads to
active_clients gauge drift over time and inaccurate total_trapped_time
data.

Testing

Each pit was tested individually by running with a 1-second sleep
followed by SIGINT, confirming clean shutdown output and no lingering
processes.

- Add SIGINT/SIGTERM signal handlers with sig_atomic_t flag
- Replace while(1) with while(keepRunning) in all four pits
- Drain client queues and emit disconnect metrics on shutdown
- Fix poll/epoll_wait to use bounded timeouts so SIGINT isn't blocked
- Handle EINTR in poll, epoll_wait, and recvfrom error paths

Affects: telnet_pit, upnp_pit, coap_pit, mqtt_pit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant