Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(net): Perform graceful network shutdown before dropping network in NetworkManager #11404

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,7 @@ impl NetworkManager {
}

NetworkHandleMessage::Shutdown(tx) => {
// Set connection status to `Shutdown`. Stops node to accept
// new incoming connections as well as sending connection requests to newly
// discovered nodes.
self.swarm.on_shutdown_requested();
// Disconnect all active connections
self.swarm.sessions_mut().disconnect_all(Some(DisconnectReason::ClientQuitting));
// drop pending connections
self.swarm.sessions_mut().disconnect_all_pending();
self.perform_network_shutdown();
let _ = tx.send(());
}
NetworkHandleMessage::ReputationChange(peer_id, kind) => {
Expand Down Expand Up @@ -966,10 +959,24 @@ impl NetworkManager {
},
}

self.perform_network_shutdown();
let res = shutdown_hook(self);
drop(graceful_guard);
res
}

/// Performs a graceful network shutdown by stopping new connections from being accepted while
/// draining current and pending connections.
fn perform_network_shutdown(&mut self) {
// Set connection status to `Shutdown`. Stops node from accepting
// new incoming connections as well as sending connection requests to newly
// discovered nodes.
self.swarm.on_shutdown_requested();
// Disconnect all active connections
self.swarm.sessions_mut().disconnect_all(Some(DisconnectReason::ClientQuitting));
// drop pending connections
self.swarm.sessions_mut().disconnect_all_pending();
}
}

impl Future for NetworkManager {
Expand Down
Loading