Repository navigation
adapter/statsclient: hold accessLock during Disconnect to avoid segfault - #391
Merged
sknat merged 1 commit intoSep 24, 2026
Merged
Conversation
Disconnect() unmapped the shared memory segment without taking accessLock, unlike reconnect() which correctly wraps disconnect()+ connect() in accessLock.Lock(). DumpStats, ListStats, PrepareDir and UpdateDir only take accessLock.RLock(), so a concurrent Disconnect() could munmap the segment while one of those was mid-read, faulting inside loadSharedHeader on the now-unmapped region. This is reachable in practice: govpp/core.StatsConnection runs a health-check goroutine that calls ListStats on its own ticker, independent of whatever locking a caller wraps around Disconnect(). Take accessLock.Lock() in Disconnect() before checking connection state and unmapping, mirroring reconnect(). Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>
|
@sknat Can you please take a look? |
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
Disconnect()unmapped the shared memory segment without takingaccessLock, unlikereconnect()which correctly wrapsdisconnect()+connect()inaccessLock.Lock().DumpStats,ListStats,PrepareDirandUpdateDironly takeaccessLock.RLock(), so a concurrentDisconnect()couldmunmapthe segment while one of those was mid-read, faulting insideloadSharedHeaderon the now-unmapped region.core.StatsConnectionruns a health-check goroutine that callsListStatson its own ticker, independent of whatever locking a caller wraps aroundDisconnect().accessLock.Lock()inDisconnect()before checking connection state and unmapping, mirroringreconnect().Test plan
go build ./adapter/... ./core/...go vet ./adapter/statsclient/...go test -race ./adapter/statsclient/...