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: deadlock on recursive emit_with_ack calls #467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 12 additions & 8 deletions socketio/src/client/raw_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,18 @@ impl RawClient {
return Ok(());
};

self.outstanding_acks.lock()?.retain_mut(|ack| {
if ack.id != id {
return true;
}
let outstanding_ack = {
let mut outstanding_acks = self.outstanding_acks.lock()?;
outstanding_acks
.iter()
.position(|ack| ack.id == id)
.map(|pos| outstanding_acks.remove(pos))
};

// If we found a matching ack, call its callback otherwise ignore it.
// The official implementation just removes the ack id on timeout:
// https://github.com/socketio/socket.io-client/blob/main/lib/socket.ts#L467-L495
if let Some(mut ack) = outstanding_ack {
if ack.time_started.elapsed() < ack.timeout {
if let Some(ref payload) = socket_packet.data {
ack.callback.deref_mut()(Payload::from(payload.to_owned()), self.clone());
Expand All @@ -293,10 +300,7 @@ impl RawClient {
}
}
}
// nope, just ignore it, the official implment just remove the ack id when timeout
// https://github.com/socketio/socket.io-client/blob/main/lib/socket.ts#L467-L495
false
});
}

Ok(())
}
Expand Down