Skip to content

Commit e84206f

Browse files
committed
protocol: Ensure the transport manager is informed about closed
connections Signed-off-by: Alexandru Vasile <[email protected]>
1 parent 62162e6 commit e84206f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/protocol/protocol_set.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,31 @@ impl ProtocolSet {
418418
})
419419
.collect::<FuturesUnordered<_>>();
420420

421+
// Capture the first error that occurs while reporting to protocols.
422+
let mut protocol_error = None;
421423
while !futures.is_empty() {
422-
if let Some(Err(error)) = futures.next().await {
423-
return Err(error.into());
424+
if let Some(Err(err)) = futures.next().await {
425+
if protocol_error.is_none() {
426+
protocol_error = Some(err.into());
427+
}
424428
}
425429
}
426430

431+
// Ensure the manager receives the connection closed event. Otherwise, the
432+
// manager will think the connection is still open, while the underlying
433+
// protocols and raw connection are closed.
427434
self.mgr_tx
428435
.send(TransportManagerEvent::ConnectionClosed {
429436
peer,
430437
connection: connection_id,
431438
})
432-
.await
433-
.map_err(From::from)
439+
.await?;
440+
441+
// If any protocol report failed, return that error now
442+
match protocol_error {
443+
Some(e) => Err(e),
444+
None => Ok(()),
445+
}
434446
}
435447
}
436448

0 commit comments

Comments
 (0)