Browse Source

run ContainerStart sequentially

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 6 months ago
parent
commit
4f6cc2a330
2 changed files with 16 additions and 1 deletions
  1. 5 0
      pkg/compose/convergence.go
  2. 11 1
      pkg/e2e/fixtures/port-range/compose.yaml

+ 5 - 0
pkg/compose/convergence.go

@@ -650,9 +650,14 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
 	return created, err
 }
 
+// force sequential calls to ContainerStart to prevent race condition in engine assigning ports from ranges
+var startMx sync.Mutex
+
 func (s *composeService) startContainer(ctx context.Context, ctr containerType.Summary) error {
 	w := progress.ContextWriter(ctx)
 	w.Event(progress.NewEvent(getContainerProgressName(ctr), progress.Working, "Restart"))
+	startMx.Lock()
+	defer startMx.Unlock()
 	err := s.apiClient().ContainerStart(ctx, ctr.ID, containerType.StartOptions{})
 	if err != nil {
 		return err

+ 11 - 1
pkg/e2e/fixtures/port-range/compose.yaml

@@ -3,4 +3,14 @@ services:
     image: nginx:alpine
     scale: 5
     ports:
-      - "6005-6015:80"
+      - "6005-6015:80"
+
+  b:
+    image: nginx:alpine
+    ports:
+      - 80
+
+  c:
+    image: nginx:alpine
+    ports:
+      - 80