-
Notifications
You must be signed in to change notification settings - Fork 2
fix: resolve race condition causing hang with current_thread runtime Closes: #1 #2
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
Merged
paolobarbolini
merged 7 commits into
M4SS-Code:main
from
ThinkerDreamer:fix/current-thread-runtime-hang
Jan 23, 2026
Merged
fix: resolve race condition causing hang with current_thread runtime Closes: #1 #2
paolobarbolini
merged 7 commits into
M4SS-Code:main
from
ThinkerDreamer:fix/current-thread-runtime-hang
Jan 23, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was previously fixed in bf98c06 but accidentally reverted during a refactor.
f4c70c9 to
6553498
Compare
Member
Author
|
Apparently the tests I added don't run on CI. |
d070f46 to
08c4ac1
Compare
Member
Author
|
I also included a fix for hardcoded |
paolobarbolini
requested changes
Jan 20, 2026
3b2e491 to
bc700c2
Compare
dodomorandi
suggested changes
Jan 21, 2026
41ff7f9 to
731d430
Compare
731d430 to
4f0a6d1
Compare
paolobarbolini
approved these changes
Jan 22, 2026
dodomorandi
approved these changes
Jan 22, 2026
The background receive task previously had a sequential flow: 1. Process pending subscriptions via try_recv() loop 2. Block on socket recv().await In a single-threaded runtime, if a subscription message arrived while the task was blocked on socket recv(), it would never be processed. When the ICMP reply arrived, it was discarded because the subscriber wasn't registered yet. This fix uses poll_fn to poll both the subscription channel and socket within the same waker context, ensuring we wake on either event. This is required for single-threaded runtimes where we can't rely on concurrent execution of the background task. Closes M4SS-Code#1
Add integration tests to prevent regression of issue M4SS-Code#1, where measure_many would hang with single-threaded Tokio runtimes. Tests: - ping_localhost_current_thread: Core regression test for issue M4SS-Code#1 - ping_localhost_multi_thread: Baseline test for comparison - ping_sequential_current_thread: Multiple sequential ping operations Also adds rt-multi-thread to dev-dependencies for the baseline test. Note: These tests require ICMP socket access, which depends on the net.ipv4.ping_group_range sysctl setting. Tests gracefully skip if ICMP sockets are unavailable, allowing CI to pass while still providing coverage on systems that support rootless ping.
The test job was hardcoded to use @stable instead of respecting the matrix-defined Rust versions (stable, beta, nightly, 1.85).
…e on invalid data Invalid data including truncated packets, wrong ICMP type, and destination unreachable. Also includes a test asserting a valid echo reply is correctly parsed.
4f0a6d1 to
9e781bd
Compare
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a race condition in the background receive task that caused
measure_manyto hang indefinitely when using tokio'scurrent_threadruntime.Closes #1
Problem
The original implementation had a race condition:
try_recv()socket.recv().awaitWith
multi_threadruntime this worked by coincidence (concurrent execution), but withcurrent_threadit caused a deadlock.Solution
Replaced the sequential polling approach with a unified
poll_fnthat polls both the subscription channel and socket receive in the same waker context. This ensures the task wakes on either event, which is required for single-threaded runtimes.Key changes:
poll_fnto combine subscription and socket polling into one futuretry_recv()as a fast-path optimization (~2x faster when messages are queued)poll_fnto persist across pollsChanges
src/pinger.rs- Refactored background receive loop to use unified pollingsrc/socket/base.rs- Set socket to non-blockingtests/runtime_compatibility.rs- Added regression tests for both runtime flavorsTesting
current_threadruntimemeasure_manyhangs withcurrent_threadtokio runtime #1