Skip to content

Commit 0957c45

Browse files
committed
runtime_vm: Avoid possible deadlock on UpdateContainerStatus()
StartContainer() function will hold the opLock, while a goroutine will be waiting for the container to terminate. Once it happens, the goroutine would update the container status, calling then UpdateContainerStatus() which will try to get the opLock and, consequently, a deadlock will happen. In order to avoid such situation, let's create the updateContainerStatus() helper, which actually does status update but does not try to get the opLock, leaving it up to the caller to do so. This new helper will be used from both StartContainer() and UpdateContainerStatus() functions. Signed-off-by: Fabiano Fidêncio <[email protected]> (cherry picked from commit faad1a4) (cherry picked from commit 2e92c0b)
1 parent 5705587 commit 0957c45

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/oci/runtime_vm.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ func (r *runtimeVM) StartContainer(c *Container) error {
258258
go func() {
259259
_, err = r.wait(r.ctx, c.ID(), "")
260260
if err == nil {
261-
err = r.UpdateContainerStatus(c)
261+
if err1 := r.updateContainerStatus(c); err1 != nil {
262+
logrus.Warningf("error updating container status %v", err1)
263+
}
262264
}
263265
}()
264266

@@ -576,6 +578,16 @@ func (r *runtimeVM) UpdateContainerStatus(c *Container) error {
576578
c.opLock.Lock()
577579
defer c.opLock.Unlock()
578580

581+
return r.updateContainerStatus(c)
582+
}
583+
584+
// updateContainerStatus is a UpdateContainerStatus helper, which actually does the container's
585+
// status refresh.
586+
// It does **not** Lock the container, thus it's the caller responsibility to do so, when needed.
587+
func (r *runtimeVM) updateContainerStatus(c *Container) error {
588+
logrus.Debug("runtimeVM.updateContainerStatus() start")
589+
defer logrus.Debug("runtimeVM.updateContainerStatus() end")
590+
579591
// This can happen on restore, for example if we switch the runtime type
580592
// for a container from "oci" to "vm" for the same runtime.
581593
if r.task == nil {

0 commit comments

Comments
 (0)