Skip to content

bug: Non-Deterministic Test shouldHonourConfiguredUpstreamConnectTimeout #5111

Closed

Description

@k-wall

failed test

Test: io.kroxylicious.it.ResilienceIT.shouldHonourConfiguredUpstreamConnectTimeout

Link: https://github.com/kroxylicious/kroxylicious/actions/runs/38568998495/job/115872398160

stack trace

java.lang.AssertionError: 

Expecting actual:
  1.983740463S
to be greater than or equal to:
  2S

at io.kroxylicious.it.ResilienceIT.shouldHonourConfiguredUpstreamConnectTimeout(ResilienceIT.java:231)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

The test validates that a configured 2-second upstream connect timeout is honored. The measured timeout was 1.983740463 seconds—only 16 milliseconds short of the expected value. This type of failure is typical of timing-sensitive tests where system load, thread scheduling, or other timing variations cause the measurement to fall just below the threshold.

Activity

  1. added
    kind/bug
    test
    on Oct 14, 2026
  2. AdityaThakur1998 commented on Oct 15, 2026

    @AdityaThakur1998
    Contributor

    Can I get assignment ?

  3. AdityaThakur1998 commented on Oct 16, 2026

    @AdityaThakur1998
    Contributor

    Flaky integration test: shouldHonourConfiguredUpstreamConnectTimeout

    The new integration test for this issue fails intermittently on CI, never locally:

    Expecting actual: 1.983740463S
    to be greater than or equal to: 2S
    

    Cause: the test times a window that starts after the thing it's measuring.

    The proxy's dial to the blackholed address is already in flight before System.nanoTime() is read. Measured by scraping the connect-initiation counter immediately after tester.admin() returns, with no describeCluster() call at all:

    moment kroxylicious_proxy_to_server_connections_total ..._errors_total
    right after tester.admin() 1.0 0.0
    +3s, still no describeCluster() 2.0 1.0

    proxyToServerConnectionCounter.increment() is the first statement in ServerConnectionStateMachine#connect, so that counter marks initiation rather than completion — the dial starts during AdminClient construction, and the connect fails on its own clock without the describe call driving it.

    So elapsed = CONNECT_TIMEOUT − gap + reconnect, where gap is the time between the dial starting and the clock being read. The gap is small — tester.admin() returns in ~1ms, getManagementClient() in ~0.2ms — but it's positive, and it sits on the wrong side of the inequality: anything that stalls in that window makes elapsed smaller.

    That leaves ~120ms of margin. Locally I measured 2123–2162ms over five runs, so it never crossed zero — but five runs of identical code also produced one outlier at 2368ms against a 2147ms minimum, so >200ms of jitter is reachable in a single JVM. On a loaded CI runner that margin isn't safe, which is why this only shows up there.

    Fix: read the clock before anything that can initiate an upstream connect.

    try (var tester = kroxyliciousTester(config);
            var managementClient = tester.getManagementClient()) {
        var startedAt = System.nanoTime();
    
        // When
        try (var admin = tester.admin()) {
            var clusterId = admin.describeCluster().clusterId();
            // Then
            ...
        }
    }

    The clock now precedes the dial, so elapsed > CONNECT_TIMEOUT + reconnect and the floor holds by construction — any pause anywhere only increases elapsed. Measured 2146–2161ms locally, well inside the 5s completion budget.

    To be clear what this does and doesn't establish: the mechanism is confirmed by measurement, and the fix removes the failure mode by inverting the inequality rather than widening a margin. I could not reproduce the CI failure locally, so I haven't demonstrated the fix prevents that specific run — but the floor is no longer sensitive to jitter at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bugtesttriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions