mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-10-20 18:56:21 +00:00
undo a previous change; close the connection if either side of the channel handed back is dropped/fails
This commit is contained in:
1 file changed
+10
-10
@@ -71,14 +71,10 @@ impl Connection {
|
|||||||
data.clear();
|
data.clear();
|
||||||
let message_data = match ws_from_connection.receive_data(&mut data).await {
|
let message_data = match ws_from_connection.receive_data(&mut data).await {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Couldn't receive data means some issue with the connection. Log
|
|
||||||
// the error, and close the other half of the connection too,
|
|
||||||
// so the associated channels close gracefully.
|
|
||||||
log::error!(
|
log::error!(
|
||||||
"Shutting down websocket connection: Failed to receive data: {}",
|
"Shutting down websocket connection: Failed to receive data: {}",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
let _ = tx_has_closed.send(());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
@@ -94,15 +90,19 @@ impl Connection {
|
|||||||
data = Vec::with_capacity(128);
|
data = Vec::with_capacity(128);
|
||||||
|
|
||||||
if let Err(e) = tx_to_external.send(msg).await {
|
if let Err(e) = tx_to_external.send(msg).await {
|
||||||
// Failure to send likely means that the recv has been dropped,
|
log::error!(
|
||||||
// so let's drop this loop too. An issue with the channel doesn't
|
"Shutting down websocket connection: Failed to send data out: {}",
|
||||||
// mean that our socket connection has failed though, so we make no
|
e
|
||||||
// attempt to close the other half of our connection here (we may
|
);
|
||||||
// still be happily sending messages even if we dropped the receiver)
|
|
||||||
log::error!("Failed to send data out: {}", e);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the receive loop ends, make sure the other half closes and let the socket
|
||||||
|
// connection be dropped. While we might want to drop half of the channel and keep
|
||||||
|
// the connection open, we need to keep receiving from it in order to ackknowledge
|
||||||
|
// control messages, so if this loops ends, we had better just shut it all down.
|
||||||
|
let _ = tx_has_closed.send(());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Receive messages externally to send to the socket.
|
// Receive messages externally to send to the socket.
|
||||||
|
|||||||
Reference in new issue
Block a user