Skip to content

adapter/statsclient: hold accessLock during Disconnect to avoid segfault - #391

Merged
sknat merged 1 commit into
FDio:masterfrom
glebkin:fix/statsclient-disconnect-race-segfault
Sep 24, 2026
Merged

sknat merged 1 commit into
FDio:masterfrom
glebkin:fix/statsclient-disconnect-race-segfault

Conversation

@glebkin

@glebkin glebkin commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 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: core.StatsConnection runs a health-check goroutine that calls ListStats on its own ticker, independent of whatever locking a caller wraps around Disconnect().
  • Fix: take accessLock.Lock() in Disconnect() before checking connection state and unmapping, mirroring reconnect().

Test plan

  • go build ./adapter/... ./core/...
  • go vet ./adapter/statsclient/...
  • go test -race ./adapter/statsclient/...

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>
@mcdoker18

Copy link
Copy Markdown

@sknat Can you please take a look?

@sknat sknat left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, thanks

@sknat
sknat merged commit c71484d into FDio:master Sep 24, 2026
11 checks passed
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.

3 participants