Skip to content

Commit 40d8c3d

Browse files
crvvianlancetaylor
authored andcommitted
internal/poll: fix deadlock in Write if len(buf) > maxRW
fd.l.Lock shouldn't be called in a loop. Change-Id: I3afbc184aa06a60175c9a39319985b5810ecb144 Reviewed-on: https://go-review.googlesource.com/c/go/+/165598 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a60b56a commit 40d8c3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/internal/poll/fd_windows.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ func (fd *FD) Write(buf []byte) (int, error) {
673673
return 0, err
674674
}
675675
defer fd.writeUnlock()
676+
if fd.isFile {
677+
fd.l.Lock()
678+
defer fd.l.Unlock()
679+
}
676680

677681
ntotal := 0
678682
for len(buf) > 0 {
@@ -683,8 +687,6 @@ func (fd *FD) Write(buf []byte) (int, error) {
683687
var n int
684688
var err error
685689
if fd.isFile {
686-
fd.l.Lock()
687-
defer fd.l.Unlock()
688690
switch fd.kind {
689691
case kindConsole:
690692
n, err = fd.writeConsole(b)

0 commit comments

Comments
 (0)