You should probably defer mutex unlock() and not use naked returns: https://github.com/pojntfx/go-nbd/blob/main/pkg/backend/file...
Defering overhead is very small nowdays.
Defering overhead is very small nowdays.
Edit: Oh I just saw the addition to your comment - that is exactly what I was thinking of ^^
> This release improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly. As a result, defer can now be used in performance-critical code without overhead concerns.
EDIT: https://github.com/golang/go/issues/14939 I believe is the main tracking bug for this.