Fix bug where connection close aborts the peer handler if it's not in Established state.
Some checks are pending
Rust / build (push) Waiting to run

This commit is contained in:
Rayhaan Jaufeerally
2024-08-08 21:09:14 +00:00
parent 5130177bf4
commit 9c9d6beede

View File

@ -640,20 +640,17 @@ where
// Close the TCP stream. // Close the TCP stream.
if let Some(stream) = self.tcp_stream.as_mut() { if let Some(stream) = self.tcp_stream.as_mut() {
match stream.shutdown().await { match stream.shutdown().await {
Ok(_) => info!("Closed TCP stream with peer: {}", self.config.name), Ok(_) => trace!("Closed TCP stream with peer: {}", self.config.name),
Err(e) => warn!( Err(_) => { /* Ignore errors since the connection is already defunct. */ }
"Failed to close TCP stream with peer {}: {}",
self.config.name,
e.to_string()
),
} }
} }
let peer_id = match &self.peer_open_msg { // If the state is open, then we cleanup the routes from this peer.
Some(peer_open_msg) => peer_open_msg.identifier, // TODO: This should only be done after the hold timer has expired but for
None => bail!("Missing peer open msg"), // simplicity we do it here now.
}; if matches!(self.state, BGPState::Established) {
if let Some(peer_open_msg) = &self.peer_open_msg {
let peer_id = peer_open_msg.identifier;
// Iterate over every route that we've announced to the route manager // Iterate over every route that we've announced to the route manager
// and withdraw it. // and withdraw it.
let mut route_withdraw = RouteWithdraw { let mut route_withdraw = RouteWithdraw {
@ -669,12 +666,16 @@ where
.send(RouteManagerCommands::Update(RouteUpdate::Withdraw( .send(RouteManagerCommands::Update(RouteUpdate::Withdraw(
route_withdraw, route_withdraw,
))) )))
.map_err(|e| std::io::Error::new(std::io::ErrorKind::BrokenPipe, e.to_string()))?; .map_err(|e| {
std::io::Error::new(std::io::ErrorKind::BrokenPipe, e.to_string())
})?;
// Clear prefixes_in. // Clear prefixes_in.
self.prefixes_in = IpLookupTable::new(); self.prefixes_in = IpLookupTable::new();
}
}
// Set the state machine back to the expected. // On any connection close we reset the state back to Active, regardless of the state we were in before.
self.state = BGPState::Active; self.state = BGPState::Active;
self.established_time = None; self.established_time = None;