Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure websocket is flushed #6347

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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