Repository navigation
tests: the port 0 hold tests ask whether the sockets the engine opened are closed, not how many sockets of the process have the port number (v1.6.0, Refs #1104) - #1171
Conversation
…d are closed, not how many sockets of the process have the port number (v1.6.0, Refs #1104)
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Socket ownership tracking internal/engine/epoll/listen_port0_owned_1104_linux_test.go, internal/engine/iouring/listen_port0_owned_1104_linux_test.go |
Both engines add inode-based trackers. The trackers identify listener sockets and discover matching port-hold sockets through /proc/self/fd. |
Listen lifecycle checks internal/engine/epoll/listen_port0_hold_895_linux_test.go, internal/engine/epoll/listen_port0_owned_1104_linux_test.go, internal/engine/iouring/listen_port0_hold_895_linux_test.go, internal/engine/iouring/listen_port0_owned_1104_linux_test.go |
The tests record engine sockets during successful and failed Listen calls and verify they close. The failed-listen tests retain the port-rebind check. |
Foreign socket cases internal/engine/epoll/listen_port0_hold_895_linux_test.go, internal/engine/iouring/listen_port0_hold_895_linux_test.go |
New subtests place a listener or an SO_REUSEPORT socket on the selected port. They check that engine-owned sockets close even when the port census finds a socket. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Other · Severity of issue fixed: Low
Possibly related issues
- Issue 1104: The changes address the test failure caused by counting a socket on the selected port without distinguishing engine-owned sockets from other process sockets.
Merge Risk: 
Minimal · up to 7dbe4
-
The updated port-0 tests have no established issue that should delay merging, subject to normal checks.
Pre-merge checks: 
3 · 
1
-
Failed checks: 1 warning Passed checks: 3 passed -
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Refs #1104. Test-only. The cause of the one CI failure is not established; this makes the next occurrence say what it is. No product bug was found.
TestPort0HoldIsReleasedWhenListenFails895(and the...IsHeldBetweenBeingChosenAndBeingBound895final check), in bothinternal/engine/iouringandinternal/engine/epoll, counted every socket of the test process whose local port equals the port the hold chose (census895). AfterListenreturns the hold is gone and the port is free, so that count also takes in a socket the process has on that port number that is not the engine's, and the failure ("1 sockets still bound to port 37483") could not tell the two apart. What the engine promises is narrower: every socket it opened for that Listen (the hold, the workers' / loops' listen sockets) is closed whenListenreturns, and the port is bindable at once.The tests now name the engine's sockets by inode while
Listenruns (the hold inportHoldHook, each listen socket inlistenAddrOf), and afterListenreturns fail if any of those inodes is still open in/proc/self/fd, with the process's sockets on the port listed. A socket of the process that is not the engine's is logged with its address and does not fail.bindWithin656/ the plain bind afterwards are kept.What I found
shutdown()/stopAccepting/releaseFailedInitcloses its listen fd on the worker's thread beforewg.Done, andhold.Close()(an*os.File, blocking, not in the poller) is deferred inListen: all synchronous beforeListenreturns. The census reads/proc/self/fd, so a socket the kernel keeps alive behind a closed fd (the io_uring: Listen returns while its listen sockets still hold the port, for ~2 ms, until the kernel tears the ring down #896 accept-reference case) is not visible to it at all.--cpus 2, 8 MiB memlock), 0 of 5000 runs of it with its predecessor under 3 busy loops, one full-package-race -vpass in the CI shape (dual stack required) green. epoll: an async route's closing response is sent whole; the EBUSY timed-wait arm reaches its wait; the port 0 hold tests name the extra socket (Refs #1068, #890, #1107, #1108, #1104) #1106 reports 0 of 35 000 and about 1 CI failure in 1 100 executions.bind(0)never lands on a port such a socket has (0 of 20 000, accepted children of closed listeners, client sockets, same-address listeners), but does land on a port a socket at another address has (127.0.0.2,::1: 2 800 of 20 000 binds with 2 000 such listeners). Also P = 37483 is odd, andbind(0)prefers odd ports whileconnect()prefers even ones, so a stray dial taking the port after the release is unlikely. So neither explanation in the issue is shown. The new check turns a recurrence into one of two outcomes: it fails naming an engine socket (a product bug, with its fd and kind), or it passes and logs the foreign owner with its address.portHoldHookorlistenAddrOf. Each test asserts it saw at least one hold and one listen socket (the IsHeld test: one per worker/loop), so a broken recording fails instead of passing empty.Evidence (golang:1.27.3 linux/arm64 container,
-race,--ulimit memlock=8388608,--cpus 2,-test.cpu 2)TestPort0FailedListenIgnoresASocketOfAnotherOwner1104, listener arm) with the old assertion put back: 20 of 20 FAIL on both engines, with the issue's message ("1 sockets still bound to port N after Listen failed, want 0"). New oracle: 30 of 30 PASS on both engines (wholeTestPort0*set).the port 0 hold); a worker's / loop's listen socket not closed (iouring shutdown; epollstopAcceptingandshutdown, 5/5 red, names the listen socket); address filter of the hold recording removed (N1: the bound-with-reuseport arm, which looks exactly like the hold but sits on127.0.0.2, 5/5 red);listenAddrOfrecording disabled (N2: 5/5 red at the "named at least one of each" check). Unmutated: green.Checks
go vetlinux/darwin/windows and-tags validation;mage apiCheck(no API change); golangci-lint 2.15 (not 2.14), also with--build-tags validation: 0 issues in the changed files (3errcheckhits inadopt_*_test.goare on main and unrelated). Not run: a full CI-shape package pass on this head (CI will).Out of scope, seen under load (
--cpus 2, 3 busy loops, 30 runs of-run '895|896'):TestListenReleasesThePortAfterALongSendDrain{Natural,SQFull}896failed 4 of 30 on its own guard ("the shutdown never reached cancelAccept").