Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: protect against concurrent map access in APIServer #6388

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Jan 10, 2024

Fixes a potential concurrency issue introduced in #6167 - it looks like during the lock refactors, we missed a couple cases.

In a past testdev run (https://github.com/dagger/dagger/actions/runs/7459047868/job/20294230186), the tests failed with:

fatal error: concurrent map read and map write

goroutine 569315 [running]:
github.com/dagger/dagger/core/schema.(*APIServer).ServeHTTP(0xc0197f3900, {0x1f9c9a0, 0xc0100aa460}, 0xc00eed5800)
	/app/core/schema/schema.go:171 +0x119
github.com/dagger/dagger/engine/server.(*DaggerServer).ServeClientConn.(*DaggerServer).HTTPHandlerForClient.func4({0x1f9c9a0, 0xc0100aa460}, 0xc0348b3660?)
	/app/engine/server/server.go:211 +0x219
net/http.HandlerFunc.ServeHTTP(0x410805?, {0x1f9c9a0?, 0xc0100aa460?}, 0xc0100aa401?)
	/usr/local/go/src/net/http/server.go:2136 +0x29
net/http.serverHandler.ServeHTTP({0x1f912f8?}, {0x1f9c9a0?, 0xc0100aa460?}, 0x6?)
	/usr/local/go/src/net/http/server.go:2938 +0x8e
net/http.(*conn).serve(0xc003f73b00, {0x1fa3018, 0xc034a38bd0})
	/usr/local/go/src/net/http/server.go:2009 +0x5f4
created by net/http.(*Server).Serve in goroutine 568703
	/usr/local/go/src/net/http/server.go:3086 +0x5cb

The map in question, clientCallContext is usually accessed behing the clientCallMu lock. There were a few instances where reads of this map were not behind this lock, so I've added these in.

In a past testdev run, the tests failed with:

	fatal error: concurrent map read and map write

	goroutine 569315 [running]:
	github.com/dagger/dagger/core/schema.(*APIServer).ServeHTTP(0xc0197f3900, {0x1f9c9a0, 0xc0100aa460}, 0xc00eed5800)
		/app/core/schema/schema.go:171 +0x119
	github.com/dagger/dagger/engine/server.(*DaggerServer).ServeClientConn.(*DaggerServer).HTTPHandlerForClient.func4({0x1f9c9a0, 0xc0100aa460}, 0xc0348b3660?)
		/app/engine/server/server.go:211 +0x219
	net/http.HandlerFunc.ServeHTTP(0x410805?, {0x1f9c9a0?, 0xc0100aa460?}, 0xc0100aa401?)
		/usr/local/go/src/net/http/server.go:2136 +0x29
	net/http.serverHandler.ServeHTTP({0x1f912f8?}, {0x1f9c9a0?, 0xc0100aa460?}, 0x6?)
		/usr/local/go/src/net/http/server.go:2938 +0x8e
	net/http.(*conn).serve(0xc003f73b00, {0x1fa3018, 0xc034a38bd0})
		/usr/local/go/src/net/http/server.go:2009 +0x5f4
	created by net/http.(*Server).Serve in goroutine 568703
		/usr/local/go/src/net/http/server.go:3086 +0x5cb

The map in question, `clientCallContext` is usually accessed behing the
`clientCallMu` lock. There were a few instances where reads of this map
were *not* behind this lock, so I've added these in.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc requested review from sipsma and gerhard January 10, 2024 11:51
Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc added this to the v0.9.6 milestone Jan 11, 2024
Copy link
Member

@TomChv TomChv left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@gerhard gerhard left a comment

Choose a reason for hiding this comment

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

👍 🚀

@jedevc jedevc merged commit 620819e into dagger:main Jan 11, 2024
43 checks passed
@jedevc jedevc deleted the fix-concurrent-call-context-map-access branch January 11, 2024 13:40
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.

None yet

3 participants