Prevent dual-mode accept tests from hanging - #133457
Merged
Merged
Conversation
Bound failed connection attempts, reserve the tested address-family port, and queue a valid connection before invoking accept so synchronous test variants cannot remain blocked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Dispose both sockets when bind retries fail to avoid resource leaks.
Pull request overview
Hardens dual-mode socket accept tests against platform-specific hangs by bounding failed connections and validating successful same-family accepts.
Changes:
- Adds explicit shadow-address support to
PortBlocker. - Bounds mismatched-family connection attempts.
- Verifies accepted endpoints across Sync, APM, EAP, and Task implementations.
File summaries
| File | Summary |
|---|---|
src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs |
Updates negative accept tests to avoid hangs and validate accepted endpoints. |
src/libraries/Common/tests/System/Net/Sockets/SocketTestExtensions.cs |
Supports explicit shadow addresses in PortBlocker. |
Review details
Suppressed comments (1)
src/libraries/Common/tests/System/Net/Sockets/SocketTestExtensions.cs:129
- When
TryBindWithoutReuseAddressreturnsfalse(the normal bind-conflict path on both Windows and Unix), this loop retries without disposing eitherMainSocketor_shadowSocket; the next iteration overwrites both references, and exhausting retries also leaks the final pair. The new explicit shadow-address call relies on these retries, so dispose both sockets before continuing wheneversuccessis false.
success = TryBindWithoutReuseAddress(_shadowSocket, shadowEndPoint, out _);
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
This was referenced Sep 17, 2026
Open
rzikm
approved these changes
Sep 18, 2026
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
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.
The negative dual-mode accept tests start an accept operation and then expect a mismatched-address-family connection to fail immediately. On macOS,
DualModeAcceptSync.AcceptV6BoundToAnyV4_CantConnectcan instead leave both operations pending indefinitely: the worker remains blocked in nativeaccept, while the connect never completes.This is the same class of problem historically discussed in #16265. These tests were later re-enabled as part of #1481 / #80715, but the shared negative helper still has unbounded operations.
This change:
PortBlockerto accept an explicit shadow address, since the socket address family does not identify the bound endpoint family for dual-mode sockets;TryConnecthelper;The change is test-only and covers the shared Sync, APM, EAP, and Task implementations.
Validation:
A full libraries baseline was not run; the focused
System.Net.Socketstest project built successfully while running the affected classes.Note
This pull request description was generated with GitHub Copilot.