Skip to content

Commit

Permalink
fix: ensure websocket is flushed (#6347)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 17, 2023
1 parent a8cb7f8 commit 141bd91
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/anvil/server/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let pin = self.get_mut();
loop {
// drive the sink
// drive the websocket
while let Poll::Ready(Ok(())) = pin.connection.poll_ready_unpin(cx) {
// only start sending if socket is ready
if let Some(msg) = pin.pending.pop_front() {
Expand All @@ -182,6 +182,14 @@ where
}
}

// Ensure any pending messages are flushed
// this needs to be called manually for tungsenite websocket: <https://github.com/foundry-rs/foundry/issues/6345>
if let Poll::Ready(Err(err)) = pin.connection.poll_flush_unpin(cx) {
trace!(target: "rpc", ?err, "websocket err");
// close the connection
return Poll::Ready(())
}

loop {
match pin.connection.poll_next_unpin(cx) {
Poll::Ready(Some(req)) => match req {
Expand Down

0 comments on commit 141bd91

Please sign in to comment.