Skip to content

Commit 030d256

Browse files
committed
Fix race condition with daemonized jailer in startVMM
When using jailer with Daemonize: true, the jailer parent process exits immediately after forking the child firecracker process. This caused a race condition where the SDK's process monitoring goroutine would detect the parent exit and send to errCh before waitForSocket() could establish the socket connection, causing startVMM to fail prematurely. This change modifies the process monitoring logic to treat a clean exit (status=0) of a daemonized jailer parent as expected behavior rather than an error condition. The goroutine now returns early in this case, allowing waitForSocket() and other initialization logic to complete normally. The actual firecracker child process continues running in daemon mode and creates the API socket as expected. Signed-off-by: Adam Thomason <adam.thomason@a17n.co.uk>
1 parent 77c9459 commit 030d256

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

machine.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,16 @@ func (m *Machine) startVMM(ctx context.Context) error {
588588
errCh := make(chan error)
589589
go func() {
590590
waitErr := m.cmd.Wait()
591+
592+
// If using daemonized jailer and parent exits cleanly,
593+
// this is expected behavior. Don't treat it as an error.
594+
// We return immediately and allow subsequent functions
595+
// (such as waitForSocket) to send any errors to channels.
596+
if m.Cfg.JailerCfg != nil && m.Cfg.JailerCfg.Daemonize && waitErr == nil {
597+
m.logger.Debugf("jailer parent exited (expected for daemonized mode)")
598+
return
599+
}
600+
591601
if waitErr != nil {
592602
m.logger.Warnf("firecracker exited: %s", waitErr.Error())
593603
} else {
@@ -606,7 +616,6 @@ func (m *Machine) startVMM(ctx context.Context) error {
606616
// second one never ends as it tries to read from empty channel.
607617
close(errCh)
608618
close(m.cleanupCh)
609-
610619
}()
611620

612621
m.setupSignals()

0 commit comments

Comments
 (0)