Skip to content

Fix concurrent map read/write when recreating containers#10379

Merged
ndeloof merged 1 commit intodocker:v2from
lrascao:gh-10319-concurrent-map-iteration
Mar 19, 2023
Merged

Fix concurrent map read/write when recreating containers#10379
ndeloof merged 1 commit intodocker:v2from
lrascao:gh-10319-concurrent-map-iteration

Conversation

@lrascao
Copy link
Contributor

@lrascao lrascao commented Mar 17, 2023

Why i did it

docker-compose.yaml

services:
  agent:
    image: python:3.7
   command: echo "Luis"

docker-compose -f docker-compose.yaml up --force-recreate --scale agent=500

fatal error: concurrent map iteration and map write

What I did

For each container, the CustomLabels map was being filled out and used as a way to pass labels to lower levels of the stack while being concurrently read by other goroutines in the process of spinning other containers. A new labels argument was added and propagated down the stack thus avoiding the need to set the map.

Related issue

fixes #10319

IMG_20230309_195856

I love it when a plan comes together

Signed-off-by: Luis Rascao <luis.rascao@gmail.com>
@lrascao lrascao force-pushed the gh-10319-concurrent-map-iteration branch from 89410f0 to ed64163 Compare March 17, 2023 10:05
}
name := getContainerName(project.Name, service, number)
tmpName := fmt.Sprintf("%s_%s", replaced.ID[:12], name)
service.CustomLabels[api.ContainerReplaceLabel] = replaced.ID
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the offending write

@lrascao lrascao marked this pull request as ready for review March 17, 2023 10:47
@laurazard laurazard requested review from a team, StefanScherer, glours, laurazard, milas, ndeloof, nicksieger and ulyssessouza and removed request for a team March 17, 2023 16:25
@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (643557d) 53.39% compared to head (ed64163) 53.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v2   #10379      +/-   ##
==========================================
+ Coverage   53.39%   53.41%   +0.01%     
==========================================
  Files         104      104              
  Lines        8939     8942       +3     
==========================================
+ Hits         4773     4776       +3     
  Misses       3646     3646              
  Partials      520      520              
Impacted Files Coverage Δ
pkg/compose/convergence.go 63.88% <100.00%> (+0.66%) ⬆️
pkg/compose/create.go 58.08% <100.00%> (-0.31%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you :)

@ndeloof ndeloof merged commit bfeb1dc into docker:v2 Mar 19, 2023
@lrascao lrascao deleted the gh-10319-concurrent-map-iteration branch March 20, 2023 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] fatal error: concurrent map iteration and map write during compose command

3 participants