Skip to content

Avoid slow parallel connect failures in SocketAsyncEventArgs test - #132931

Open
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:mizupan-microsoft-issue-132059-failures
Open

Avoid slow parallel connect failures in SocketAsyncEventArgs test#132931
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:mizupan-microsoft-issue-132059-failures

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Fixes #132059

Summary

SocketAsyncEventArgsTest.Connect_Parallel_Fails used IPv4 and IPv6 sockets that were bound but not listening. On macOS, connecting to such sockets can remain pending rather than fail promptly, causing the test to exceed its 30-second timeout.

Use the test suite's reserved unused port instead. This still exercises parallel IPv4 and IPv6 connection failures while avoiding OS-dependent behavior for bound, non-listening ports.

Validation

  • Required clr+libs baseline build passed.
  • Connect_Parallel_Fails passed 50 consecutive local runs.
  • All 2,500 System.Net.Sockets functional tests passed locally.
  • Repeated on osx.26.arm64.open Helix using the same macOS runtime payload:

Across two macOS ARM64 machines per version, the original setup varied from approximately 8 to 19 seconds per completed test, while the updated test consistently completed in under 101 milliseconds. This confirms that the original setup has substantial OS-dependent latency and that using the reserved unused port removes it.

Note

This description was drafted with GitHub Copilot.

@MihaZupan MihaZupan added this to the 12.0.0 milestone Aug 29, 2026
@MihaZupan MihaZupan self-assigned this Aug 29, 2026
Copilot AI lite review requested due to automatic review settings August 29, 2026 22:02
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Pull request overview

This PR updates a flaky/slow System.Net.Sockets functional test that exercises Socket.ConnectAsync(..., ConnectAlgorithm.Parallel) failure behavior, by switching the target endpoint from a bound-but-not-listening port (which can hang on macOS) to the test suite’s reserved unused port to force prompt connection refusal.

Changes:

  • Replace the per-test bound sockets/PortBlocker setup with DualModeBase.UnusedPort for a predictable “connection refused” failure.
  • Simplify the Socket.ConnectAsync invocation by using SocketType.Stream / ProtocolType.Tcp constants directly.
File summaries
File Description
src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs Reworks Connect_Parallel_Fails to use the reserved unused port to avoid OS-dependent connect latency/timeouts (notably on macOS).
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +1134 to 1136
// A bound but non-listening port can time out instead of refusing connections on macOS.
saea.RemoteEndPoint = new DnsEndPoint("localhost", DualModeBase.UnusedPort);
saea.Completed += (_, _) => mres.Set();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: System.Net.Sockets.Tests.SocketAsyncEventArgsTest.Connect_Parallel_Fails - Completed did not get called in time

2 participants