Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces improvements to the orchestrator's sandbox metrics reader and NBD dispatch logging. Specifically, it adds a guard in the metrics reader to prevent a race condition during process exit, and downgrades expected errors (such as context cancellations during shutdown or response-write failures on a closing socket) from Error to Warn level in the NBD dispatch loop. I have no feedback to provide as there are no review comments to assess.
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.
5aad415 to
d71980e
Compare
After a VM exits, in-flight NBD operations fail with context.Canceled and socket writes fail with "use of closed network connection" or "broken pipe". All of these were logged at ERROR level, generating noise that drowns out real failures. dispatch.go: - Downgrade "nbd backend read/write failed" to Warn when the error is context.Canceled or context.DeadlineExceeded. - Downgrade "nbd error cmd read/write" (fatal-channel-full path) to Warn; shutdown is already in progress at that point. fc_metrics.go: - Add a non-blocking Exit.Done() check after ticker.C fires to handle the Go select race where both channels become ready simultaneously. This prevents a spurious "failed to flush fc metrics" Warn log when Firecracker has already exited. Fixes: e2b-dev#3274 Fixes: e2b-dev#3275
bc37151 to
b37ac80
Compare
|
Thanks for this, @AdaAibaby. I'm closing it because it has been inactive for 80 days and no longer merges cleanly with main. Feel free to reopen it, or open a fresh PR against current main, if you'd like to continue. The issue stays open. |
When a Firecracker VM exits, in-flight NBD commands and the reply socket
fail in predictable ways that are not backend faults:
- cmdRead/cmdWrite/cmdWriteZeroes select on the dispatch context, so an
in-flight backend call observes context.Canceled (or DeadlineExceeded)
the moment the sandbox is torn down.
- completeAsync's reply-socket write fails with "use of closed network
connection" (net.ErrClosed) or "broken pipe" (EPIPE) once the client
side is gone.
All four paths logged these at Error, so every normal teardown with
in-flight I/O produced a burst of ERROR lines that drown out the real
backend failures Error is meant to surface (e2b-dev#3274).
Introduce isExpectedTeardownError (context.Canceled, context.DeadlineExceeded,
net.ErrClosed, syscall.EPIPE) and route all four failure logs through a new
logCmdFailure helper that downgrades those to Warn and keeps everything else
at Error. Genuine backend errors (corrupt block, ECONNRESET, unexpected EOF)
still surface at Error.
Adds dispatch_teardown_test.go: a table-driven test over the classifier
covering wrapped context errors, net.ErrClosed/EPIPE inside *net.OpError (how
a closed-socket write actually surfaces), and the negatives that must stay
Error.
Scope note: this PR revives only the NBD-dispatch half of the closed e2b-dev#3277.
Its other half — the FC metrics flusher select-race guard (e2b-dev#3275) — is
already fixed on main by 50c64be ("stop flushing Firecracker metrics after
the VM exits"), so it is intentionally left out. e2b-dev#3275 is CLOSED COMPLETED;
e2b-dev#3274 is still open. Adapted to main's refactor (single completeAsync error
log, command.fields(), injected d.logger). Closes e2b-dev#3274. Supersedes e2b-dev#3277.
Summary
Closes #3274
Closes #3275
After a Firecracker VM exits (normally or abnormally), two sources of spurious ERROR-level logs appear:
NBD dispatch (
dispatch.go): In-flight reads/writes fail withcontext.Canceledand response writes fail withuse of closed network connection/broken pipe. All were logged at ERROR, generating noise that drowns out real backend failures.FC metrics flusher (
fc_metrics.go): A Goselectrace betweenp.Exit.Done()andticker.Ccan causeflushMetrics()to be called against a dead Firecracker socket, emitting a spurious"failed to flush fc metrics: connection reset by peer"Warn log even after the process has exited.Changes
packages/orchestrator/pkg/sandbox/nbd/dispatch.gonbd backend read/write failed: downgrade to Warn whenerrors.Is(err, context.Canceled || context.DeadlineExceeded); keep ERROR for real backend failuresnbd error cmd read/write(fatal-channel-full path): downgrade to Warn; by the time this path is reached, shutdown is already in progresspackages/orchestrator/pkg/sandbox/fc/fc_metrics.gocase <-ticker.Cfires, add a non-blockingselect { case <-p.Exit.Done(): return; default: }guard to handle the race where both channels are simultaneously readyBefore / After
Before (every sandbox teardown with in-flight I/O):
After:
Real backend errors (non-canceled) still surface at ERROR level.
Test plan
kill -9while I/O is in-flight; confirm no ERROR logs fornbd backend read/write failedwithcontext canceled"failed to flush fc metrics"Warn disappears after VM exit/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.