Summary
The #657 fix (PR #681) stops the io_uring hand-off from releasing a connection's fd while an operation on it can still resolve the fd. The close paths keep the same shape. They are listed here as the follow-up the #657 design deferred (DECISION step 5). This is found by reading and not observed in any run so far.
finishClose / finishCloseDetached submit the connection's cancels (cancelConnOps) and then unix.Close the fd at once. A linked RECV that has not been issued yet (still in the SQ ring, or chained behind a SEND) resolves the fd number when it is issued. By then a new accept may hold that number.
hijackConn hands the fd to net.FileConn with only a pending cancel for the armed recv. A recv that completes before the cancel lands takes the hijacker's first bytes.
shutdown closes connection fds before tearing down the ring.
On 5.10-5.18 kernels the cancels themselves fail (#682), which makes the close-path case far worse. That half is tracked there. This issue is about the ordering on kernels where the cancels work.
What a fix needs
Related: #657, #682, PR #681.
Summary
The #657 fix (PR #681) stops the io_uring hand-off from releasing a connection's fd while an operation on it can still resolve the fd. The close paths keep the same shape. They are listed here as the follow-up the #657 design deferred (DECISION step 5). This is found by reading and not observed in any run so far.
finishClose/finishCloseDetachedsubmit the connection's cancels (cancelConnOps) and thenunix.Closethe fd at once. A linked RECV that has not been issued yet (still in the SQ ring, or chained behind a SEND) resolves the fd number when it is issued. By then a new accept may hold that number.hijackConnhands the fd tonet.FileConnwith only a pending cancel for the armed recv. A recv that completes before the cancel lands takes the hijacker's first bytes.shutdowncloses connection fds before tearing down the ring.On 5.10-5.18 kernels the cancels themselves fail (#682), which makes the close-path case far worse. That half is tracked there. This issue is about the ordering on kernels where the cancels work.
What a fix needs
close()a connection's fd while any op on it can still resolve the fd. Either hold the close until the kernel owes nothing (kernelInflight == 0and no recv armed), or make sure the RECV is issued before the fd can be reused.Related: #657, #682, PR #681.