Skip to content

deferred-lock-after-lock

Detect deferring Lock immediately after locking.

Updated View as Markdown

Default severity: error

Deferring Lock or RLock immediately after acquiring the same lock is almost always a typo for deferring Unlock or RUnlock and is likely to deadlock when the function returns.

Bad

mutex.Lock()
defer mutex.Lock()

Good

mutex.Lock()
defer mutex.Unlock()
Navigation

Type to search…

↑↓ navigate↵ selectEsc close