瀏覽代碼

[Bug]Fix race between sandbox.delete() and SetKey()

When sandbox is deleting, another SetKey routine could be also in
progress as there's no lock to protect it, when this happens, there
could be a scene that one sandbox is removed, but it's osSbox file
"/var/run/docker/netns/xxxx" left on system and will never be cleaned.

So add a inDelete check for SetKey() to eliminate the race.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Zhang Wei 8 年之前
父節點
當前提交
0f17689abf
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      libnetwork/sandbox.go

+ 4 - 0
libnetwork/sandbox.go

@@ -626,6 +626,10 @@ func (sb *sandbox) SetKey(basePath string) error {
 	}
 	}
 
 
 	sb.Lock()
 	sb.Lock()
+	if sb.inDelete {
+		sb.Unlock()
+		return types.ForbiddenErrorf("failed to SetKey: sandbox %q delete in progress", sb.id)
+	}
 	oldosSbox := sb.osSbox
 	oldosSbox := sb.osSbox
 	sb.Unlock()
 	sb.Unlock()