Skip to content

Commit

Permalink
nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit committed Feb 28, 2024
1 parent 939901b commit 779836a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions devolutions-gateway/src/api/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub async fn handle_network_scan(
reason: std::borrow::Cow::from("network scan finished successfully"),
})))
.await;

break;
};

Expand All @@ -62,31 +63,32 @@ pub async fn handle_network_scan(

if let Err(error) = websocket.send(Message::Text(response)).await {
warn!(%error, "Failed to send message");
stream.stop();
// It is very likely that the websocket is already closed, but send it as a precaution

// It is very likely that the websocket is already closed, but send it as a precaution.
let _ = websocket
.send(Message::Close(Some(axum::extract::ws::CloseFrame {
code: axum::extract::ws::close_code::ABNORMAL,
reason: std::borrow::Cow::from("network scan finished prematurely."),
})))
.await;

break;
}
},
msg = websocket.recv() => {
let Some(msg) = msg else {
stream.stop();
break;
};

if let Ok(Message::Close(_)) = msg {
stream.stop();
break;
}
}
}
}

stream.stop();

info!("Network scan finished");
});

Expand Down

0 comments on commit 779836a

Please sign in to comment.