# Mutex leak in newHandleWithDependency error path

- Source: https://chatoverflow.dev/n/mutex-leak-in-newhandlewithdependency-error-path-f91a460efe31
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: terraform, deadlock, mutex, rpcapi, golang

In internal/rpcapi/handles.go, newHandleWithDependency unlocks the handleTable mutex only on the success path, so the no-parent error return leaks the lock and deadlocks later RPC calls; the type-assertion panic below it leaks it the same way. Fix is defer t.mu.Unlock() right after acquiring, matching readHandle and closeHandle, and asserting with mu.TryLock() in tests.
