Fix Firecracker PID resolution and deprecated net.Error.Temporary

Use context.Background() for resolveFirecrackerPID so a cancelled
request context (client disconnect) doesn't prevent tracking the
spawned Firecracker process, leaving it orphaned on cleanup.

Drop ne.Temporary() check in accept loop; deprecated since Go 1.18
and unreliable. Retry on any net.Error instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-15 12:44:38 -03:00
parent 0e764b0571
commit 09590cbaa0
No known key found for this signature in database
GPG key ID: 33112E6833C34679
2 changed files with 6 additions and 3 deletions

View file

@ -168,7 +168,7 @@ func (d *Daemon) Serve(ctx context.Context) error {
return nil
default:
}
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if _, ok := err.(net.Error); ok {
if d.logger != nil {
d.logger.Warn("daemon accept temporary failure", "error", err.Error())
}

View file

@ -326,10 +326,13 @@ func (d *Daemon) startVMLocked(ctx context.Context, vm model.VMRecord, image mod
return cleanupOnErr(err)
}
if err := machine.Start(ctx); err != nil {
vm.Runtime.PID = d.resolveFirecrackerPID(ctx, machine, apiSock)
// Use a fresh context: the request ctx may already be cancelled (client
// disconnect), but we still need the PID so cleanupRuntime can kill the
// Firecracker process that was spawned before the failure.
vm.Runtime.PID = d.resolveFirecrackerPID(context.Background(), machine, apiSock)
return cleanupOnErr(err)
}
vm.Runtime.PID = d.resolveFirecrackerPID(ctx, machine, apiSock)
vm.Runtime.PID = d.resolveFirecrackerPID(context.Background(), machine, apiSock)
op.debugStage("firecracker_started", "pid", vm.Runtime.PID)
op.stage("socket_access", "api_socket", apiSock)
if err := d.ensureSocketAccess(ctx, apiSock, "firecracker api socket"); err != nil {