Skip to content

copy-lock-value

Detect values that copy sync locks.

Updated View as Markdown

Default severity: error

Copying a value that contains sync.Mutex or sync.RWMutex creates an independent lock state and can invalidate the intended synchronization. Pass such values by pointer and avoid value receivers, assignments, and returns that copy them.

Bad

func update(state State) {
	state.mu.Lock()
	defer state.mu.Unlock()
}

Good

func update(state *State) {
	state.mu.Lock()
	defer state.mu.Unlock()
}
Navigation

Type to search…

↑↓ navigate↵ selectEsc close