Go version
go version go1.24.2 linux/amd64
Output of go env
in your module/workspace:
n/a
What did you do?
are these lines missing a defer:
https://cs.opensource.google/go/go/+/master:src/database/sql/sql.go;l=2309 https://cs.opensource.google/go/go/+/master:src/database/sql/sql.go;l=2341
If not, maybe consider improving the comment for clarity
What did you see happen?
n/a
What did you expect to see?
n/a
Comment From: gabyhelp
Related Issues
- why this line don't need the defer? #28305 (closed)
- database/sql/sql.go: I wonder why 'defer' is not used to release mutex in the '(db *DB) putConn' function. #39814 (closed)
- defer #37460 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: Jorropo
https://go-review.googlesource.com/c/go/+/250178/comment/01beeeb2_9f28b1ae/ too
Comment From: mrkfrmn
Thanks for raising this — it strikes me as more of a question than a Go bug. We don't use the issue tracker for general questions; for that, you should consider the wiki page.
At least on my read of the CL @Jorropo linked, it seems it was an intentional decision not to defer
— but I could be wrong.
CC'ing @kardianos. Also closing as this does not seem to be a bug.
Comment From: vkolesn
After looking into more details, this is legit indeed. tx.closemu
is an RW lock and this barrier waits for other connections to finish. This was not very clear to me from the comment initially.