---
title: "copy-lock-value"
description: "Detect values that copy sync locks."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# copy-lock-value

**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

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

## Good

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

Source: https://strider.gempir.com/analyzers/copy-lock-value/index.mdx
