Skip to content

Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774

Open
rzikm wants to merge 1 commit intodotnet:mainfrom
rzikm:fix/ping-ttl-increase
Open

Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774
rzikm wants to merge 1 commit intodotnet:mainfrom
rzikm:fix/ping-ttl-increase

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Mar 19, 2026

SendPingWithLowTtl_RoundtripTimeIsNonZero has been consistently failing on macOS since it was introduced (Mar 11, 29 failures across 17 builds on both osx.15.amd64 and osx.26.arm64).

Root Cause

The test sends a ping with TTL=1 and asserts that the TtlExpired reply has RoundtripTime > 0. On macOS, the raw socket Ping implementation computes RTT via:

long roundTripTime = (long)Stopwatch.GetElapsedTime(startingTimestamp).TotalMilliseconds;

The (long) cast truncates sub-millisecond values to 0. On CI machines, the first-hop router responds to TTL=1 pings in under 1ms, so all 3 retry attempts report RoundtripTime == 0.

This doesn't affect Windows, which uses IcmpSendEcho with 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

…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>
Copilot AI review requested due to automatic review settings March 19, 2026 13:46
@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

/azp run runtime-libraries coreclr-outerloop

@dotnet-policy-service
Copy link
Contributor

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

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

/azp runtime-coreclr libraries-outerloop

@azure-pipelines
Copy link

Command 'runtime-coreclr' is not supported by Azure Pipelines.

Supported commands
  • help:
    • Get descriptions, examples and documentation about supported commands
    • Example: help "command_name"
  • list:
    • List all pipelines for this repository using a comment.
    • Example: "list"
  • run:
    • Run all pipelines or specific pipelines for this repository using a comment. Use this command by itself to trigger all related pipelines, or specify specific pipelines to run.
    • Example: "run" or "run pipeline_name, pipeline_name, pipeline_name"
  • where:
    • Report back the Azure DevOps orgs that are related to this repository and org
    • Example: "where"

See additional documentation.

@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

/azp run runtime-coreclr libraries-outerloop

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

/azp list

@azure-pipelines
Copy link

CI/CD Pipelines for this repository:

@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rzikm rzikm requested a review from a team March 19, 2026 13:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_RoundtripTimeIsNonZero from 1 to 5.
  • 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.

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.

3 participants