Skip to content

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented Mar 17, 2025

Description of changes:

After doing some testing, the current dispatch queue closing logic has a potential race condition where the queue can end up being freed twice. This change fixes that by locking both receivers in the same order (to avoid a deadlock) and observing the other side's status before deciding to free the queue or not.

Call-outs:

I did a little more clean up around tracing events by creating actual probes instead. I've also tried to avoid calling any of the probes while holding a mutex.

Testing:

I added a stress test that was able to reproduce the original issue and show that the changes fixed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft marked this pull request as ready for review March 17, 2025 20:30
drop(inner);

// drop wakers after the lock to avoid potential mutex poisoning
wakers.dont_wake();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we waking somewhere else? Otherwise it seems like this will hang a potential read(...) when the stream closes? Or maybe that doesn't actually get hit in practice?

(I think this is not changed in this PR, so not super relevant, but might be another deadlock risk)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called from the receivers themselves so in almost all cases they shouldn't be set. This is mostly for if one of the receivers drops prematurely before getting notified of a new packet.

@camshaft camshaft merged commit c591b3f into main Mar 17, 2025
125 of 126 checks passed
@camshaft camshaft deleted the camshaft/dc-recv-dispatch-fixes branch March 17, 2025 21:01
Mark-Simulacrum pushed a commit to Mark-Simulacrum/s2n-quic that referenced this pull request Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants