Skip to content

device, cmd/check-lockorder: add static analysis tool for lock ordering#56

Merged
bradfitz merged 1 commit intotailscalefrom
bradfitz/lockchecker
Apr 27, 2026
Merged

device, cmd/check-lockorder: add static analysis tool for lock ordering#56
bradfitz merged 1 commit intotailscalefrom
bradfitz/lockchecker

Conversation

@bradfitz
Copy link
Copy Markdown
Member

This adds cmd/check-lockorder, a static analyzer that builds a
lock-after directed graph from the device package and reports cycles
(potential deadlocks) and reentrant RLocks (which deadlock with a
pending writer), and hook it up to CI to fail so we don't regress.

This also does some no-op (I believe) refactoring of some device code
to make locking easier for both humans and cmd/check-lockorder to follow,
without having to hard-code exceptions in cmd/check-lockorder or make
it more complicated.

This is the tool that previously found the deadlock fixed by 770e3f5.

Updates tailscale/tailscale#19513

This adds cmd/check-lockorder, a static analyzer that builds a
lock-after directed graph from the device package and reports cycles
(potential deadlocks) and reentrant RLocks (which deadlock with a
pending writer), and hook it up to CI to fail so we don't regress.

This also does some no-op (I believe) refactoring of some device code
to make locking easier for both humans and cmd/check-lockorder to follow,
without having to hard-code exceptions in cmd/check-lockorder or make
it more complicated.

This is the tool that previously found the deadlock fixed by 770e3f5.

Updates tailscale/tailscale#19513

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@bradfitz bradfitz requested a review from raggi April 26, 2026 19:29
Comment thread device/pools.go

func (device *Device) GetOutboundElementsContainer() *QueueOutboundElementsContainer {
c := device.pool.outboundElementsContainer.Get().(*QueueOutboundElementsContainer)
c.Mutex = sync.Mutex{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i had forgotten this was here, this is super dangerous

Copy link
Copy Markdown
Member

@raggi raggi left a comment

Choose a reason for hiding this comment

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

I focused my review on the wireguard side stuff. cmd/check-lockorder looks plausible, but it's a good chunk of code without tests, we might want to add tests if we're gunna use it long term.

@bradfitz bradfitz merged commit e3ac4a0 into tailscale Apr 27, 2026
14 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.

2 participants