Synchronize the in-memory checkpoint manager#522
Open
PratikDhanave wants to merge 3 commits into
Open
Conversation
inMemoryManager.Store (and its per-session caches) had no synchronization, but the manager is keyed by session ID and NewInMemoryManager carries no single-use caveat -- so sharing one manager across concurrent workflow runs (distinct sessions) is a natural pattern. Concurrent Commit calls then race on the map and can crash with 'fatal: concurrent map writes'. Guard Store with a mutex in Commit, Lookup, and RetrieveIndex. The critical sections are pure in-memory map/cache operations (no I/O), so holding the lock across each method is cheap. Adds TestInMemoryManager_ConcurrentSessions_NoRace: 64 goroutines commit and read distinct sessions concurrently; it reports data races under -race before this change and passes after.
There was a problem hiding this comment.
Pull request overview
Synchronizes the in-memory checkpoint Manager implementation to prevent concurrent access races when a single inMemoryManager is shared across multiple concurrent workflow sessions.
Changes:
- Added a mutex to
inMemoryManagerand guardedCommit,Lookup, andRetrieveIndexto protect the sessionStoremap and per-session caches. - Added an internal concurrency test intended to reproduce the prior race under
-raceand validate the fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| workflow/checkpoint/manager.go | Adds a sync.Mutex to inMemoryManager and locks around Store/cache access in key methods. |
| workflow/checkpoint/manager_race_internal_test.go | Adds a concurrent multi-session test to validate race-free behavior under -race. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
inMemoryManager(workflow/checkpoint/manager.go) has an unsynchronizedStore map[string]*SessionCacheand per-session caches. The manager is keyed by session ID, andNewInMemoryManagerdocuments no single-use restriction — so sharing one manager across concurrent workflow runs (distinct sessions committing at the same time) is a natural pattern. Under that use, concurrentCommitcalls race on the map and can crash the process withfatal: concurrent map writes.Under
-race, a handful of concurrent commits reliably report data races on theStoreaccess insessionStore.Fix
Guard
Storewith async.MutexinCommit,Lookup, andRetrieveIndex. The critical sections are pure in-memory map/cache operations (no I/O), so holding the lock across each method is cheap.Public API
No exported symbols change.
Tests
Adds
TestInMemoryManager_ConcurrentSessions_NoRace(internal test): 64 goroutinesCommitandRetrieveIndexdistinct sessions concurrently. It reports data races under-racebefore this change and passes after.go test -race ./workflow/checkpointpasses;go build ./...andgo vetclean; gofumpt clean.