Implement Graceful Shutdown with Connection Draining - #145
Open
veemakama wants to merge 2 commits into
Open
Conversation
- Add tokio-util dep for CancellationToken - Add shutdown: CancellationToken param to run_gossip_loop; cancelled() branch is the first arm in select! so it is always checked - Add disconnect_all() to TransportManager; drains active_connections and clears pending_messages; shutdown() delegates to it - Add connected_peers() helper to TransportManager - Add close() to MeshDatabase; issues PRAGMA wal_checkpoint(TRUNCATE) before returning - Implement full shutdown sequence in stellarconduitd.rs: CancellationToken root + child token for gossip, JoinHandle stored, SIGTERM handled alongside ctrl_c, 2 s pending-message flush, 3 s gossip join timeout, disconnect_all, db.close() Tests added: - test_gossip_loop_exits_on_cancellation (protocol.rs) - test_disconnect_all_clears_connections (unified.rs) - test_database_close_checkpoints_wal (persistence_test.rs) - test_daemon_exits_within_5_seconds (daemon_shutdown_test.rs) Closes StellarConduit#47
…n-draining
feat(daemon): implement graceful shutdown with connection draining
Changes
Cargo.toml
Add tokio-util = { version = "0.7", features = ["rt"] } for CancellationToken
src/gossip/protocol.rs
Add shutdown: CancellationToken parameter to run_gossip_loop
Add shutdown.cancelled() as the first select! arm so it is always polled
src/transport/unified.rs
Add disconnect_all(): drains active_connections, clears pending_messages, logs completion
Add connected_peers(): returns pubkeys of all live connections
shutdown() now delegates to disconnect_all() (backwards compatible)
src/persistence/db.rs
Add close(): issues PRAGMA wal_checkpoint(TRUNCATE) via conn.call, then logs
src/bin/stellarconduitd.rs
Full shutdown sequence:
CancellationToken root; child token passed to gossip loop
Handles both ctrl_c and SIGTERM
Calls shutdown.cancel()
2 s deadline to flush GossipState::active_queue to connected peers
3 s timeout to join the gossip JoinHandle
disconnect_all() on the transport manager
db.close() for WAL checkpoint
Tests added
Test Location
test_gossip_loop_exits_on_cancellation src/gossip/protocol.rs
test_disconnect_all_clears_connections src/transport/unified.rs
test_database_close_checkpoints_wal tests/persistence_test.rs
test_daemon_exits_within_5_seconds tests/daemon_shutdown_test.rs
Acceptance criteria
run_gossip_loop exits cleanly when its CancellationToken is cancelled
TransportManager::disconnect_all() exists and drains active_connections
MeshDatabase::close() issues WAL checkpoint before returning
Daemon handles SIGTERM and exits within 5 s
Pending queue flushed to connected peers before shutdown (2 s deadline)
All existing tests updated to pass the new shutdown arg
Closes StellarConduit#119
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #119