From 0f17689abfbbd6610ff412baea98f46a8f850a24 Mon Sep 17 00:00:00 2001 From: Zhang Wei Date: Thu, 25 May 2017 15:17:34 +0800 Subject: [PATCH] [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 --- libnetwork/sandbox.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index c820cc04e9..d9c846c0a5 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -626,6 +626,10 @@ func (sb *sandbox) SetKey(basePath string) error { } sb.Lock() + if sb.inDelete { + sb.Unlock() + return types.ForbiddenErrorf("failed to SetKey: sandbox %q delete in progress", sb.id) + } oldosSbox := sb.osSbox sb.Unlock()