fix(nbd): downgrade broken-pipe socket errors from ERROR to WARN#3296
fix(nbd): downgrade broken-pipe socket errors from ERROR to WARN#3296AdaAibaby wants to merge 2 commits into
Conversation
When a sandbox shuts down, in-flight NBD response writes to the kernel Unix socket fail with EPIPE. These are logged at ERROR in the cmdRead/cmdWrite/cmdWriteZeroes default branches (reached when the fatal channel is already occupied), generating spurious error bursts on every normal sandbox termination. Add isSocketClosed() to detect EPIPE/ErrClosedPipe and emit WARN instead. Unexpected socket errors (non-EPIPE) remain at ERROR.
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function isSocketClosed to detect when an NBD Unix socket is closed by a peer, and updates the cmdRead, cmdWrite, and cmdWriteZeroes dispatch functions to log these expected socket closures as warnings rather than errors. The review feedback suggests a refactoring to dynamically assign the logging function to a variable, which avoids duplicating the extensive list of logging fields across the if/else branches in each of these methods.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem
When a sandbox VM terminates, the NBD dispatch loop has in-flight goroutines that try to write responses back to the kernel via the Unix socket. Since the socket is already closed, these writes fail with EPIPE ("broken pipe"). The first failure is sent to the
fatalchannel; all subsequent concurrent goroutines hit thedefault:branch and log at ERROR:This generates a burst of ERROR-level log noise on every normal sandbox shutdown, making it harder to spot real failures.
Fix
Add
isSocketClosed()to detectsyscall.EPIPEandio.ErrClosedPipeand emit WARN instead of ERROR in thedefault:branches ofcmdRead,cmdWrite, andcmdWriteZeroes. Unexpected non-EPIPE errors remain at ERROR.This is the write-side counterpart of the read-side
ErrObjectNotExistdowngrade already in dispatch.go.Test plan