]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.12] internal/poll: fix deadlock in Write if len(buf) > maxRW
authorIan Lance Taylor <iant@golang.org>
Wed, 3 Apr 2019 22:30:13 +0000 (15:30 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 4 Apr 2019 02:24:05 +0000 (02:24 +0000)
fd.l.Lock shouldn't be called in a loop.

Manual backport of CL 165598. It could not be cherry-picked due to conflicts.

Fixes #31211

Change-Id: Ib76e679f6a276b32fe9c1594b7e9a506017a7967
Reviewed-on: https://go-review.googlesource.com/c/go/+/170680
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/poll/fd_windows.go

index 19d9a12dad83b9b9e1d388c113328fc0dc409bea..f860b82c97489e4e30c8cb3e28ae20f9ca8aed4f 100644 (file)
@@ -660,6 +660,10 @@ func (fd *FD) Write(buf []byte) (int, error) {
                return 0, err
        }
        defer fd.writeUnlock()
+       if fd.isFile || fd.isDir || fd.isConsole {
+               fd.l.Lock()
+               defer fd.l.Unlock()
+       }
 
        ntotal := 0
        for len(buf) > 0 {
@@ -670,8 +674,6 @@ func (fd *FD) Write(buf []byte) (int, error) {
                var n int
                var err error
                if fd.isFile || fd.isDir || fd.isConsole {
-                       fd.l.Lock()
-                       defer fd.l.Unlock()
                        if fd.isConsole {
                                n, err = fd.writeConsole(b)
                        } else {