From e2bae93a2b4c468312fd7f6a3ea8ac35f468b623 Mon Sep 17 00:00:00 2001 From: Hamza El-Saawy Date: Mon, 14 Nov 2022 14:06:40 -0500 Subject: [PATCH] race condition with exitCh in `(*UtilityVM).Start()` `(*UtilityVM).acceptAndClose()` waits on `(*UtilityVM).exitCh`, but `exitCh` is not created until after the goroutines with the `acceptAndClose` calls are launched, causing a potential race condition. Functional and cri-containerd tests pass. Signed-off-by: Hamza El-Saawy --- internal/uvm/start.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/uvm/start.go b/internal/uvm/start.go index 634783bc2e..69daaa6e69 100644 --- a/internal/uvm/start.go +++ b/internal/uvm/start.go @@ -158,6 +158,10 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) { }() defer cancel() + // create exitCh ahead of time to prevent race conditions between writing + // initalizing the channel and waiting on it during acceptAndClose + uvm.exitCh = make(chan struct{}) + // Prepare to provide entropy to the init process in the background. This // must be done in a goroutine since, when using the internal bridge, the // call to Start() will block until the GCS launches, and this cannot occur @@ -208,7 +212,6 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) { }() // Start waiting on the utility VM. - uvm.exitCh = make(chan struct{}) go func() { err := uvm.hcsSystem.Wait() if err == nil {