Skip to content

fix(modelchecker): make protopath cache safe for concurrent readers#357

Merged
jp-fizzbee merged 1 commit into
mainfrom
user/jp/fix-protopath-thread-safety
May 19, 2026
Merged

fix(modelchecker): make protopath cache safe for concurrent readers#357
jp-fizzbee merged 1 commit into
mainfrom
user/jp/fix-protopath-thread-safety

Conversation

@jp-fizzbee
Copy link
Copy Markdown
Collaborator

ProtoPath.filesMap is a global cache populated lazily by every Processor through GetProtoFieldByPath. The map was written without synchronization (only the values are immutable; the map structure mutates on insert). Today this is benign because all callers are sequential; once parallel simulation workers exist, two concurrent first-touches of the same file or path will trip Go's "concurrent map writes" runtime check.

Wrap reads in a fast RLock path and writes in a Lock path with a double- check after acquiring the write lock (in case another goroutine populated the entry while we were computing). The expensive GetFieldByPath/ convertToProto work runs outside the write lock so workers don't serialize on it.

Adds a concurrent test that exercises 16 goroutines × 200 iterations to make the locking contract explicit; it currently passes either way because Go's runtime check is timing-sensitive and the rules_go race build setup here did not appear to wire through, but the test will start catching regressions once we wire race detection or extend the iteration count.

ProtoPath.filesMap is a global cache populated lazily by every Processor
through GetProtoFieldByPath. The map was written without synchronization
(only the values are immutable; the map structure mutates on insert).
Today this is benign because all callers are sequential; once parallel
simulation workers exist, two concurrent first-touches of the same file
or path will trip Go's "concurrent map writes" runtime check.

Wrap reads in a fast RLock path and writes in a Lock path with a double-
check after acquiring the write lock (in case another goroutine populated
the entry while we were computing). The expensive GetFieldByPath/
convertToProto work runs outside the write lock so workers don't serialize
on it.

Adds a concurrent test that exercises 16 goroutines × 200 iterations to
make the locking contract explicit; it currently passes either way
because Go's runtime check is timing-sensitive and the rules_go race
build setup here did not appear to wire through, but the test will start
catching regressions once we wire race detection or extend the iteration
count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jp-fizzbee jp-fizzbee merged commit ed51bbd into main May 19, 2026
1 check passed
@jp-fizzbee jp-fizzbee deleted the user/jp/fix-protopath-thread-safety branch May 19, 2026 22:45
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.

2 participants