Skip to content

Commit

Permalink
Fix deadlock (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 authored Oct 5, 2023
1 parent 1518baa commit 9020725
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/client-api/src/routes/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ async fn ws_client_actor(client: ClientConnection, mut ws: WebSocketStream, mut
log::debug!("Client connection ended");
sendrx.close();

// clear the queue before we go on to clean up, or else we can get a situation like:
// https://rust-lang.github.io/wg-async/vision/submitted_stories/status_quo/aws_engineer/solving_a_deadlock.html
handle_queue.clear();

// ignore NoSuchModule; if the module's already closed, that's fine
let _ = client.module.subscription().remove_subscriber(client.id);
let _ = client
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/util/future_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ where
pub fn push_unpin(&mut self, item: T) {
self.queue.push_back(item)
}
pub fn clear(self: Pin<&mut Self>) {
let mut me = self.project();
me.queue.clear();
me.fut.set(Fuse::terminated());
}
}

impl<T, F, Fut> Stream for FutureQueue<T, F, Fut>
Expand Down

0 comments on commit 9020725

Please sign in to comment.