Skip to content

integration: deflake TestFailFastWhenConnectShim - #13471

Merged
mxpv merged 1 commit into
containerd:mainfrom
samuelkarp:deflake-TestFailFastWhenConnectShim
May 30, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
samuelkarp:deflake-TestFailFastWhenConnectShim

Conversation

@samuelkarp

Copy link
Copy Markdown
Member

In high-load CI environments,
TestFailFastWhenConnectShim/normal-unix-socket-v2 flaked with:
expected error connection refused, but got <nil>
at shim_dial_unix_test.go:134.

Diagnosis:
For normal Unix sockets (filesystem-backed, where
SetUnlinkOnClose(false) is called to keep the socket file), closing the socket listener does not guarantee that subsequent dials instantly fail with ECONNREFUSED in the OS kernel. Under high parallel contention, the kernel-side transition of the socket file structure to the refusing state is deferred for a brief window. The test immediately dials the address after close, which unexpectedly succeeds under load, flaking the test.

Reproduction:
We successfully reproduced the flake inside an almalinux/9 Vagrant VM (running with nested virtualization inside a GCE VM) under parallel load, where the test failed exactly on iteration 3 of the integration suite loop.

Solution:

  1. Remove manual listener.Close() and rely entirely on ttrpcSrv.Shutdown(ctx) to close the listener, preventing double-close races.
  2. Use a 5-second timeout context for Shutdown to prevent CI hangs if a connection leaks.
  3. Implement a robust 2-second polling helper pollECONNREFUSED inside the test that dials in a 10ms loop (using a 100ms dial timeout to avoid blocking) until it receives syscall.ECONNREFUSED.
  4. Assert require.NoError(t, pollECONNREFUSED(addr)) immediately after Shutdown to ensure the OS has fully unlinked/closed the socket before running the main assertions.

Tested:
Verified by executing 15 parallel integration test runs inside the preserved AlmaLinux 9 Vagrant guest VM. All 15 runs passed successfully (100% success rate).

Assisted-by: Antigravity

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.

Pull request overview

This PR deflakes the Unix shim dial integration test by making shutdown and post-shutdown dial behavior more robust under high-load CI conditions, where closing a Unix socket listener may not immediately yield ECONNREFUSED on subsequent dials.

Changes:

  • Adds a polling helper to wait until dials reliably return ECONNREFUSED after shutting down the ttrpc server.
  • Uses a bounded timeout context for ttrpcSrv.Shutdown and removes the immediate manual listener close in favor of shutdown-driven closure.
  • Switches to testify/require assertions for the new shutdown/polling checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread integration/shim_dial_unix_test.go Resolved
In high-load CI environments,
TestFailFastWhenConnectShim/normal-unix-socket-v2 flaked with:
  expected error connection refused, but got <nil>
at shim_dial_unix_test.go:134.

Diagnosis:
For normal Unix sockets (filesystem-backed, where
SetUnlinkOnClose(false) is called to keep the socket file), closing
the socket listener does not guarantee that subsequent dials
instantly fail with ECONNREFUSED in the OS kernel. Under high
parallel contention, the kernel-side transition of the socket file
structure to the refusing state is deferred for a brief window.
The test immediately dials the address after close, which
unexpectedly succeeds under load, flaking the test.

Reproduction:
We successfully reproduced the flake inside an almalinux/9 Vagrant VM
(running with nested virtualization inside a GCE VM) under parallel
load, where the test failed exactly on iteration 3 of the integration
suite loop.

Solution:
1. Remove manual listener.Close() and rely entirely on
ttrpcSrv.Shutdown(ctx) to close the listener, preventing double-close
races.
2. Use a 5-second timeout context for Shutdown to prevent CI hangs if a
connection leaks.
3. Implement a robust 2-second polling helper pollECONNREFUSED inside
the test that dials in a 10ms loop (using a 100ms dial timeout to avoid
blocking) until it receives syscall.ECONNREFUSED.
4. Assert require.NoError(t, pollECONNREFUSED(addr)) immediately after
Shutdown to ensure the OS has fully unlinked/closed the socket before
running the main assertions.

Tested:
Verified by executing 15 parallel integration test runs inside the
preserved AlmaLinux 9 Vagrant guest VM. All 15 runs passed
successfully (100% success rate).

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <[email protected]>
@samuelkarp
samuelkarp force-pushed the deflake-TestFailFastWhenConnectShim branch from d98974f to a9fba66 Compare May 22, 2026 20:15
@samuelkarp

Copy link
Copy Markdown
Member Author

Comment thread integration/shim_dial_unix_test.go Resolved
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review May 30, 2026
@mxpv
mxpv added this pull request to the merge queue May 30, 2026
Merged via the queue into containerd:main with commit 561fcdb May 30, 2026
157 of 164 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants