fix websocket hangup error (#1981)

This commit is contained in:
Aiden McClelland
2022-11-28 10:35:39 -07:00
parent 2b0efb32c1
commit 415cfcb72f

View File

@@ -86,9 +86,10 @@ async fn ws_handler<
.with_kind(ErrorKind::Network)?; .with_kind(ErrorKind::Network)?;
} }
let mut ws_closed = false;
while let Some(entry) = tokio::select! { while let Some(entry) = tokio::select! {
a = logs.try_next() => Some(a?), a = logs.try_next() => Some(a?),
a = stream.try_next() => { a.with_kind(crate::ErrorKind::Network)?; None } a = stream.try_next() => { a.with_kind(crate::ErrorKind::Network)?; ws_closed = true; None }
} { } {
if let Some(entry) = entry { if let Some(entry) = entry {
let (_, log_entry) = entry.log_entry()?; let (_, log_entry) = entry.log_entry()?;
@@ -101,6 +102,7 @@ async fn ws_handler<
} }
} }
if !ws_closed {
stream stream
.close(Some(CloseFrame { .close(Some(CloseFrame {
code: CloseCode::Normal, code: CloseCode::Normal,
@@ -108,6 +110,7 @@ async fn ws_handler<
})) }))
.await .await
.with_kind(ErrorKind::Network)?; .with_kind(ErrorKind::Network)?;
}
Ok(()) Ok(())
} }