---
title: "deferred-lock-after-lock"
description: "Detect deferring Lock immediately after locking."
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.

# deferred-lock-after-lock

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

```go
mutex.Lock()
defer mutex.Lock()
```

## Good

```go
mutex.Lock()
defer mutex.Unlock()
```

Source: https://strider.gempir.com/analyzers/deferred-lock-after-lock/index.mdx
