A taken Docker host port costs the MongoDB replica set test host a retry, not the whole replica test class #399

Merged
claude merged 2 commits from feature/386-mongodb-replica-host-port-retry into develop 2026-11-13 00:25:55 -05:00
Owner

A host port that is taken when Docker binds it now costs the MongoDB replica set test host a retry with new ports, not every replica test. Test code only.

  • Failure: twice in CI (pull-request runs 1487 and 1505) Docker answered failed to bind host port 0.0.0.0:<port>/tcp: address already in use when the replica set's first member started, and all 21 tests of the five MongoDB replica classes failed in 1 ms.
  • Cause: the host reserves three ports, releases them and publishes each as the same host port, because the replica set must know its ports before the containers start. Nothing holds a number until Docker binds it, and in CI the check runs in the toolchain container's network namespace while Docker binds on the host.
  • Fix: ReplicatedEngineHost.RetryOnPortConflictAsync retries the first member's start with three new ports, at most five times, when the failure names a port conflict; any other failure surfaces at once. The three ports are drawn together, so they are distinct, and probed on every address, as Docker binds them. The other engine hosts let Docker pick the host port and need nothing.

Verified

  • PortConflictRetryTests (4 tests on the helper) and the 21 MongoDB replica tests pass (25 of 25, on real containers); build 0 warnings; csharpier clean on the changed folders.
  • Verifier: forced a real collision on this machine and confirmed that the Docker.DotNet.DockerApiException message matches the retry's check and that a failed start is disposed with no stale state; accepted. Its low findings (loopback-only probe, possible duplicate ports, a missing summary) are fixed in the second commit.
  • Not covered by an automatic test: the retry inside the MongoDB host itself, which has no seam to force a taken port.

Closes #386

🤖 Generated with Claude Code

https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK

A host port that is taken when Docker binds it now costs the MongoDB replica set test host a retry with new ports, not every replica test. Test code only. - **Failure:** twice in CI (pull-request runs 1487 and 1505) Docker answered `failed to bind host port 0.0.0.0:<port>/tcp: address already in use` when the replica set's first member started, and all 21 tests of the five MongoDB replica classes failed in 1 ms. - **Cause:** the host reserves three ports, releases them and publishes each as the same host port, because the replica set must know its ports before the containers start. Nothing holds a number until Docker binds it, and in CI the check runs in the toolchain container's network namespace while Docker binds on the host. - **Fix:** `ReplicatedEngineHost.RetryOnPortConflictAsync` retries the first member's start with three new ports, at most five times, when the failure names a port conflict; any other failure surfaces at once. The three ports are drawn together, so they are distinct, and probed on every address, as Docker binds them. The other engine hosts let Docker pick the host port and need nothing. **Verified** - `PortConflictRetryTests` (4 tests on the helper) and the 21 MongoDB replica tests pass (25 of 25, on real containers); build 0 warnings; csharpier clean on the changed folders. - Verifier: forced a real collision on this machine and confirmed that the `Docker.DotNet.DockerApiException` message matches the retry's check and that a failed start is disposed with no stale state; accepted. Its low findings (loopback-only probe, possible duplicate ports, a missing summary) are fixed in the second commit. - Not covered by an automatic test: the retry inside the MongoDB host itself, which has no seam to force a taken port. Closes #386 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The host reserves three ports before its containers start, and nothing holds them until Docker binds them. A start that Docker refuses because a host port is taken now disposes the first member, picks three new ports and tries again, up to five attempts. Any other start failure surfaces at once. The retry lives once in ReplicatedEngineHost. The other replicated hosts let Docker assign their host ports and need no retry.

Closes #386

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The MongoDB replica set test host draws three distinct ports and probes every address for them
All checks were successful
Build / Build Binary (macos-arm64) (push) Successful in -1m11s
Build / Build Binary (windows-amd64) (push) Successful in -1m1s
Build / Smoke Test the Windows Binary (push) Successful in 16s
Build / Build Arch Linux Packages (push) Successful in -2m10s
Build / Build and Push Image (push) Successful in -2m32s
Build / Build and Test Deb and RPM Packages (push) Successful in -24s
Build / Publish Release (push) Successful in -2m34s
Build / Pipeline (push) Successful in 0s
Build / Test .NET on Windows (pull_request) Has been skipped
Build / Compute Version (pull_request) Successful in -2m32s
Build / Test Admin Console (pull_request) Successful in -1m38s
Build / Lint and Script Tests (pull_request) Successful in -1m58s
Build / Windows Test Gate (pull_request) Successful in -2m38s
Build / Test .NET (pull_request) Successful in 3m43s
Build / Stage Draft Release (pull_request) Successful in -2m36s
Build / Pack and Push NuGet Packages (common) (pull_request) Successful in -2m29s
Build / Pack and Push NuGet Packages (dhcp) (pull_request) Successful in -2m11s
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Successful in -2m12s
Build / Pack and Push NuGet Packages (dns-server) (pull_request) Successful in -2m1s
Build / Build Binary (linux-amd64) (pull_request) Successful in -1m14s
Build / Build Binary (linux-arm64) (pull_request) Successful in -56s
Build / Build Binary (macos-amd64) (pull_request) Successful in -1m3s
Build / Build Binary (macos-arm64) (pull_request) Successful in -1m9s
Build / Build Binary (windows-amd64) (pull_request) Successful in -55s
Build / Smoke Test the Windows Binary (pull_request) Successful in 15s
Build / Build Arch Linux Packages (pull_request) Successful in -2m23s
Build / Build and Test Deb and RPM Packages (pull_request) Successful in -37s
Build / Build and Push Image (pull_request) Successful in -1m45s
Build / Publish Release (pull_request) Successful in -2m25s
Build / Pipeline (pull_request) Successful in 0s
c98e68c21b
Refs #386

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
claude merged commit 2f83582986 into develop 2026-11-13 00:25:55 -05:00
claude deleted branch feature/386-mongodb-replica-host-port-retry 2026-11-13 00:25:55 -05:00
Sign in to join this conversation.
No reviewers
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil!399
No description provided.