Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774
Open
rzikm wants to merge 1 commit intodotnet:mainfrom
Open
Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774rzikm wants to merge 1 commit intodotnet:mainfrom
rzikm wants to merge 1 commit intodotnet:mainfrom
Conversation
…S flakiness The test was consistently failing on macOS (both osx.15.amd64 and osx.26.arm64) because the first-hop router responds to TTL=1 pings in <1ms, and the raw socket implementation truncates sub-millisecond RTT to 0 via (long) cast. Using TTL=5 allows the packet to travel further, increasing the chance of a measurable (>0ms) round-trip time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run runtime-libraries coreclr-outerloop |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
|
No pipelines are associated with this pull request. |
Member
Author
|
/azp runtime-coreclr libraries-outerloop |
|
Command 'runtime-coreclr' is not supported by Azure Pipelines. Supported commands
See additional documentation. |
Member
Author
|
/azp run runtime-coreclr libraries-outerloop |
|
No pipelines are associated with this pull request. |
Member
Author
|
/azp list |
Member
Author
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts a flaky System.Net.Ping OuterLoop test on macOS by increasing the TTL used for a TtlExpired/TimeExceeded scenario so the measured round-trip time is more likely to be non-zero.
Changes:
- Increase TTL in
SendPingWithLowTtl_RoundtripTimeIsNonZerofrom1to5. - Add explanatory comments describing the macOS raw-socket RTT truncation behavior and why a higher TTL helps.
Comments suppressed due to low confidence (1)
src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs:832
- Setting options.Ttl = 5 can cause the ping to reach the configured external host when it is within <=5 hops, which would produce IPStatus.Success and fail the assertion that requires TimeExceeded/TtlExpired. To keep this test robust across network topologies, consider dynamically selecting a TTL that results in a non-Success status (e.g., probe with increasing TTL to find hop count and then use a smaller TTL), or skip the test when the host is too close for the chosen TTL.
// Use TTL=5 instead of 1 to increase the chance of a measurable (>0ms) round-trip
// time. On macOS, the raw socket implementation truncates sub-millisecond RTT to 0,
// and the first-hop router often responds in <1ms.
options.Ttl = 5;
bool gotNonZeroRtt = false;
for (int attempt = 0; attempt < 3; attempt++)
{
PingReply pingReply = await ping.SendPingAsync(host, TestSettings.PingTimeout, payload, options);
You can also share your feedback on Copilot code review. Take the survey.
ManickaP
approved these changes
Mar 19, 2026
This was referenced Mar 19, 2026
Open
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.
SendPingWithLowTtl_RoundtripTimeIsNonZerohas been consistently failing on macOS since it was introduced (Mar 11, 29 failures across 17 builds on bothosx.15.amd64andosx.26.arm64).Root Cause
The test sends a ping with
TTL=1and asserts that theTtlExpiredreply hasRoundtripTime > 0. On macOS, the raw socket Ping implementation computes RTT via:The
(long)cast truncates sub-millisecond values to 0. On CI machines, the first-hop router responds toTTL=1pings in under 1ms, so all 3 retry attempts reportRoundtripTime == 0.This doesn't affect Windows, which uses
IcmpSendEchowith OS-reported RTT values.Fix
Increase TTL from 1 to 5 so the ICMP packet travels further before expiring, increasing the likelihood of a measurable (>0ms) round-trip time.
Example failure log: https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-heads-main-3b34e246c46a48c489/System.Net.Ping.Functional.Tests/3/console.52343950.log?helixlogtype=result