Skip to content

Commit 2d4afb8

Browse files
authored
Fix concurrent cache map race in fillInIDs lock planning
Build query dependency trees before collecting cache locks so fillInIDs holds read locks for all resources it may traverse, preventing concurrent map read/write panics under stress.
1 parent 2de135a commit 2d4afb8

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

core/concurrent_cache/concurrent_cache.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,16 @@ func assembleQueries(queries [][]Subquery) (roots [][]int, cachesPresent map[res
402402
if err != nil {
403403
return nil, nil, false, false, err
404404
}
405-
for _, sq := range q {
405+
queries[i], roots[i] = buildTrees(ri, q)
406+
for _, sq := range queries[i] {
406407
if sq.newKey != "" {
407408
hasNewKeys = true
408409
}
410+
cachesPresent[sq.res] = struct{}{}
409411
if sq.op != list && sq.op != inconsistentRead {
410412
hasConsistentLocks = true
411413
}
412414
}
413-
queries[i], roots[i] = buildTrees(ri, q)
414-
// Include synthetic read dependencies added by buildTree so fillInIDs holds cache RLocks.
415-
for _, sq := range queries[i] {
416-
cachesPresent[sq.res] = struct{}{}
417-
}
418415
}
419416

420417
return roots, cachesPresent, hasConsistentLocks, hasNewKeys, nil

0 commit comments

Comments
 (0)