device, cmd/check-lockorder: add static analysis tool for lock ordering#56
Merged
device, cmd/check-lockorder: add static analysis tool for lock ordering#56
Conversation
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>
raggi
reviewed
Apr 27, 2026
|
|
||
| func (device *Device) GetOutboundElementsContainer() *QueueOutboundElementsContainer { | ||
| c := device.pool.outboundElementsContainer.Get().(*QueueOutboundElementsContainer) | ||
| c.Mutex = sync.Mutex{} |
Member
There was a problem hiding this comment.
i had forgotten this was here, this is super dangerous
raggi
approved these changes
Apr 27, 2026
Member
raggi
left a comment
There was a problem hiding this comment.
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.
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.
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