1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:50:22 -07:00

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Wèi Cōngruì 2019-03-06 03:23:46 +00:00 committed by Ian Lance Taylor
parent a60b56adbe
commit 40d8c3d3e8

View File

@ -673,6 +673,10 @@ func (fd *FD) Write(buf []byte) (int, error) {
return 0, err
}
defer fd.writeUnlock()
if fd.isFile {
fd.l.Lock()
defer fd.l.Unlock()
}
ntotal := 0
for len(buf) > 0 {
@ -683,8 +687,6 @@ func (fd *FD) Write(buf []byte) (int, error) {
var n int
var err error
if fd.isFile {
fd.l.Lock()
defer fd.l.Unlock()
switch fd.kind {
case kindConsole:
n, err = fd.writeConsole(b)