Skip to content

Commit dd20bf4

Browse files
committed
libcontainerd/supervisor: fix data race
The monitorDaemon() goroutine calls startContainerd() then blocks on <-daemonWaitCh to wait for it to exit. The startContainerd() function would (re)initialize the daemonWaitCh so a restarted containerd could be waited on. This implementation was race-free because startContainerd() would synchronously initialize the daemonWaitCh before returning. When the call to start the managed containerd process was moved into the waiter goroutine, the code to initialize the daemonWaitCh struct field was also moved into the goroutine. This introduced a race condition. Move the daemonWaitCh initialization to guarantee that it happens before the startContainerd() call returns. Signed-off-by: Cory Snider <[email protected]>
1 parent f5cf22c commit dd20bf4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

libcontainerd/supervisor/remote_daemon.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ func (r *remote) startContainerd() error {
190190
runtime.LockOSThread()
191191
defer runtime.UnlockOSThread()
192192
err := cmd.Start()
193-
startedCh <- err
194193
if err != nil {
194+
startedCh <- err
195195
return
196196
}
197-
198197
r.daemonWaitCh = make(chan struct{})
198+
startedCh <- nil
199+
199200
// Reap our child when needed
200201
if err := cmd.Wait(); err != nil {
201202
r.logger.WithError(err).Errorf("containerd did not exit successfully")

0 commit comments

Comments
 (0)