Skip to content

Commit 62c4026

Browse files
committed
Always decrement the WebSocket count
A previously-added early exit could cause the counter to be incremented and never decremented — oops!
1 parent b8ef5d1 commit 62c4026

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ui/src/server_axum/websocket.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
2-
metrics::{DURATION_WS, LIVE_WS},
3-
parse_channel, parse_crate_type, parse_edition, parse_mode,
2+
metrics, parse_channel, parse_crate_type, parse_edition, parse_mode,
43
sandbox::{self, Sandbox},
54
Error, ExecutionSnafu, Result, SandboxCreationSnafu, WebSocketTaskPanicSnafu,
65
};
@@ -120,10 +119,18 @@ impl From<sandbox::ExecuteResponse> for ExecuteResponse {
120119
}
121120
}
122121

123-
pub async fn handle(mut socket: WebSocket) {
124-
LIVE_WS.inc();
122+
pub async fn handle(socket: WebSocket) {
123+
metrics::LIVE_WS.inc();
125124
let start = Instant::now();
126125

126+
handle_core(socket).await;
127+
128+
metrics::LIVE_WS.dec();
129+
let elapsed = start.elapsed();
130+
metrics::DURATION_WS.observe(elapsed.as_secs_f64());
131+
}
132+
133+
async fn handle_core(mut socket: WebSocket) {
127134
if !connect_handshake(&mut socket).await {
128135
return;
129136
}
@@ -187,10 +194,6 @@ pub async fn handle(mut socket: WebSocket) {
187194

188195
drop((tx, rx, socket));
189196
tasks.shutdown().await;
190-
191-
LIVE_WS.dec();
192-
let elapsed = start.elapsed();
193-
DURATION_WS.observe(elapsed.as_secs_f64());
194197
}
195198

196199
async fn connect_handshake(socket: &mut WebSocket) -> bool {

0 commit comments

Comments
 (0)