The MongoDB replica set test host fails every replica test when Docker finds one of its reserved host ports taken #386

Closed
opened 2026-11-12 14:12:11 -05:00 by claude · 0 comments
Owner

Twenty-one Ninlil.Dns.Data.Integration.Tests failed in the Linux test job of pull-request run 1487 (PR #385, attempt 1). Seen once. Test code only; the PR does not touch this project.

Failure

  • Every test of MongoDbReplicaSetTests, MongoDbReplicaCacheTests, MongoDbReplicaHealthTests, MongoDbReplicaRoutingTests and MongoDbReplicaWebHostTests failed in 1 ms, because the shared fixture did not start.
  • MongoDbReplicaSetEngineHost.StartAsync (line 48): Docker answered failed to bind host port 0.0.0.0:34131/tcp: address already in use.

Cause

  • MongoDbReplicaSetEngineHost reserves three ports with a port-0 TCP bind on loopback, releases them, and publishes each as the same host port (WithPortBinding(published, published)). The replica set needs to know its ports before the containers start, so the reserve-and-release cannot be replaced by a Docker-assigned port.
  • Nothing holds the number between the release and Docker's bind. In CI the test process also runs in a toolchain container, so "free" is checked in that container's network namespace while Docker binds on the host. The push run of the same commit (run 1486) was running on asgard at the same time.

Fix (proposal)

  • When starting the first member fails with "address already in use" / "failed to bind host port", dispose the member, pick three new ports and try again, a bounded number of times, with a comment that says why (AGENTS.md, Test: reserve-and-release rule). Check whether the other replicated engine hosts in Ninlil.Dns.Data.EngineHosts publish fixed host ports the same way.

Done when

  • A host port that is taken when Docker binds it costs a retry, not the whole class.
Twenty-one `Ninlil.Dns.Data.Integration.Tests` failed in the Linux test job of pull-request run 1487 (PR #385, attempt 1). Seen once. Test code only; the PR does not touch this project. **Failure** - Every test of `MongoDbReplicaSetTests`, `MongoDbReplicaCacheTests`, `MongoDbReplicaHealthTests`, `MongoDbReplicaRoutingTests` and `MongoDbReplicaWebHostTests` failed in 1 ms, because the shared fixture did not start. - `MongoDbReplicaSetEngineHost.StartAsync` (line 48): Docker answered `failed to bind host port 0.0.0.0:34131/tcp: address already in use`. **Cause** - `MongoDbReplicaSetEngineHost` reserves three ports with a port-0 TCP bind on loopback, releases them, and publishes each as the same host port (`WithPortBinding(published, published)`). The replica set needs to know its ports before the containers start, so the reserve-and-release cannot be replaced by a Docker-assigned port. - Nothing holds the number between the release and Docker's bind. In CI the test process also runs in a toolchain container, so "free" is checked in that container's network namespace while Docker binds on the host. The push run of the same commit (run 1486) was running on asgard at the same time. **Fix (proposal)** - When starting the first member fails with "address already in use" / "failed to bind host port", dispose the member, pick three new ports and try again, a bounded number of times, with a comment that says why (AGENTS.md, Test: reserve-and-release rule). Check whether the other replicated engine hosts in `Ninlil.Dns.Data.EngineHosts` publish fixed host ports the same way. **Done when** - A host port that is taken when Docker binds it costs a retry, not the whole class.
Sign in to join this conversation.
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#386
No description provided.