aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2026-01-30 14:26:57 +0100
committerQuim Muntal <quimmuntal@gmail.com>2026-02-04 11:54:32 -0800
commit045d1270a7c299c6e40cccf3776860749abfe18e (patch)
treee54a9bafc9fd7381ab25e3707e6983762f820d90 /src
parentbd1b41eb8131a503a1a8d2fc41d3e79bce159468 (diff)
downloadgo-045d1270a7c299c6e40cccf3776860749abfe18e.tar.xz
internal/poll: unlock read lock if write lock fails in readWriteLock
If the write lock acquisition fails, the read lock acquired earlier is not released, leading to a potential deadlock. The deadlock shouldn't occur because when the write lock fails, it indicates that the FD is closing, and no other goroutine should be holding the read lock. However, better to be safe and release the read lock in such cases. Change-Id: If593c36040a97357f835b42bb3133ff1dc55a638 Reviewed-on: https://go-review.googlesource.com/c/go/+/740560 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/internal/poll/fd_mutex.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/internal/poll/fd_mutex.go b/src/internal/poll/fd_mutex.go
index f71c7739a1..aa8f425235 100644
--- a/src/internal/poll/fd_mutex.go
+++ b/src/internal/poll/fd_mutex.go
@@ -254,7 +254,11 @@ func (fd *FD) writeUnlock() {
// readWriteLock adds a reference to fd and locks fd for reading and writing.
// It returns an error when fd cannot be used for reading and writing.
func (fd *FD) readWriteLock() error {
- if !fd.fdmu.rwlock(true) || !fd.fdmu.rwlock(false) {
+ if !fd.fdmu.rwlock(true) {
+ return errClosing(fd.isFile)
+ }
+ if !fd.fdmu.rwlock(false) {
+ fd.fdmu.rwunlock(true) // unlock read lock acquired above
return errClosing(fd.isFile)
}
return nil