Skip to content
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
34 changes: 28 additions & 6 deletions src/protocol/protocol_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,31 +396,53 @@ impl ProtocolSet {
) -> crate::Result<()> {
let mut futures = self
.protocols
.values()
.map(|sender| async move {
.iter()
.map(|(protocol, sender)| async move {
sender
.tx
.send(InnerTransportEvent::ConnectionClosed {
peer,
connection: connection_id,
})
.await
.inspect_err(|err| {
tracing::debug!(
target: LOG_TARGET,
%protocol,
?peer,
?connection_id,
?err,
"failed to report connection closed to protocol",
);
})
})
.collect::<FuturesUnordered<_>>();

// Capture the first error that occurs while reporting to protocols.
let mut protocol_error = None;
while !futures.is_empty() {
if let Some(Err(error)) = futures.next().await {
return Err(error.into());
if let Some(Err(err)) = futures.next().await {
if protocol_error.is_none() {
protocol_error = Some(err.into());
}
}
}

// Ensure the manager receives the connection closed event. Otherwise, the
// manager will think the connection is still open, while the underlying
// protocols and raw connection are closed.
self.mgr_tx
.send(TransportManagerEvent::ConnectionClosed {
peer,
connection: connection_id,
})
.await
.map_err(From::from)
.await?;

// If any protocol report failed, return that error now
match protocol_error {
Some(e) => Err(e),
None => Ok(()),
}
}
}

Expand Down
Loading