c8d/list: Fix race condition when traversing containers#48367
c8d/list: Fix race condition when traversing containers#48367vvoland merged 3 commits intomoby:masterfrom
Conversation
|
Hmm. So wondering; should synchronization for this happen in the memory store itself? I see it has locking, but (iiuc) for the store itself, and it looks like a RWMutex taking a read lock. However, the slice returned does not dereference the container; is the problem in that area? Should it either return a copy of the container, or should locking happen for each container? 😬 moby/container/memory_store.go Line 86 in d8f079d |
35c8422 to
50a0335
Compare
|
@thaJeztah - There's no need to lock the container object itself, if the caller doesn't really mutate the container (like we do here), so it wouldn't make sense to lock inside |
|
The only reason why this sneaked past me is:
|
ec83ce6 to
5ea8392
Compare
|
Ah, dang; linting failure somewhere |
Use a regular for loop instead of ApplyAll which spawns a separate goroutine for each separate container. Signed-off-by: Paweł Gronowski <[email protected]>
Signed-off-by: Paweł Gronowski <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
4333166 to
025727f
Compare
|
I fixed teh linting issue; problem was in the imports; diff --git a/daemon/containerd/image_list_test.go b/daemon/containerd/image_list_test.go
index 50ba317e03..28b61db4b5 100644
--- a/daemon/containerd/image_list_test.go
+++ b/daemon/containerd/image_list_test.go
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
- "github.com/docker/docker/container"
"math/rand"
"os"
"path/filepath"
@@ -23,6 +22,7 @@ import (
"github.com/containerd/log/logtest"
"github.com/containerd/platforms"
imagetypes "github.com/docker/docker/api/types/image"
+ "github.com/docker/docker/container"
daemonevents "github.com/docker/docker/daemon/events"
"github.com/docker/docker/internal/testutils/specialimage"
"github.com/opencontainers/go-digest" |
Verify that the ImageData.Containers contains the ID of the container using that image. Signed-off-by: Paweł Gronowski <[email protected]>
025727f to
55f693e
Compare
- What I did
Fix a panic spotted in #47983 (comment).
Shared state is mutated inside a function which is called asynchronously:
moby/container/memory_store.go
Lines 69 to 83 in 4f0d95f
Unfortunately, it looks like the race detector doesn't pick this up for some reason.
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)