Skip to content

Commit

Permalink
fix websocket hangup error (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Nov 29, 2022
1 parent 2b0efb3 commit 415cfcb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions backend/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ async fn ws_handler<
.with_kind(ErrorKind::Network)?;
}

let mut ws_closed = false;
while let Some(entry) = tokio::select! {
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 {
let (_, log_entry) = entry.log_entry()?;
Expand All @@ -101,13 +102,15 @@ async fn ws_handler<
}
}

stream
.close(Some(CloseFrame {
code: CloseCode::Normal,
reason: "Log Stream Finished".into(),
}))
.await
.with_kind(ErrorKind::Network)?;
if !ws_closed {
stream
.close(Some(CloseFrame {
code: CloseCode::Normal,
reason: "Log Stream Finished".into(),
}))
.await
.with_kind(ErrorKind::Network)?;
}

Ok(())
}
Expand Down

0 comments on commit 415cfcb

Please sign in to comment.