Skip to content

Commit e43ee71

Browse files
committed
websocket: Decrement metrics on connection closed
Signed-off-by: Alexandru Vasile <[email protected]>
1 parent 17786b6 commit e43ee71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/transport/websocket/connection.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ impl WebSocketConnection {
436436
})
437437
}
438438

439-
/// Start connection event loop.
440-
pub(crate) async fn start(mut self) -> crate::Result<()> {
439+
async fn start_inner(mut self) -> crate::Result<()> {
441440
self.protocol_set
442441
.report_connection_established(self.peer, self.endpoint)
443442
.await?;
@@ -602,4 +601,14 @@ impl WebSocketConnection {
602601
}
603602
}
604603
}
604+
605+
/// Start connection event loop.
606+
pub(crate) async fn start(mut self) -> crate::Result<()> {
607+
self.start_inner().await.inspect_err(|_| {
608+
if let Some(metrics) = &self.metrics {
609+
// All pending substreams must be decremented because the connection is closing.
610+
metrics.pending_substreams_num.sub(self.pending_substreams.len() as u64);
611+
}
612+
})
613+
}
605614
}

0 commit comments

Comments
 (0)