1
0
mirror of https://github.com/golang/go synced 2024-11-17 07:45:09 -07:00

internal/poll: if poller init fails, assume blocking mode

Fixes #23943

Change-Id: I16e604872f1615963925ec3c4710106bcce1330c
Reviewed-on: https://go-review.googlesource.com/99015
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ian Lance Taylor 2018-03-06 14:12:45 -08:00
parent 42ecf39e85
commit 558769a61b
2 changed files with 40 additions and 1 deletions

View File

@ -59,7 +59,13 @@ func (fd *FD) Init(net string, pollable bool) error {
fd.isBlocking = true
return nil
}
return fd.pd.init(fd)
err := fd.pd.init(fd)
if err != nil {
// If we could not initialize the runtime poller,
// assume we are using blocking mode.
fd.isBlocking = true
}
return err
}
// Destroy closes the file descriptor. This is called when there are

View File

@ -587,3 +587,36 @@ func TestRacyWrite(t *testing.T) {
}()
}
}
// Closing a TTY while reading from it should not hang. Issue 23943.
func TestTTYClose(t *testing.T) {
f, err := os.Open("/dev/tty")
if err != nil {
t.Skipf("skipping because opening /dev/tty failed: %v", err)
}
go func() {
var buf [1]byte
f.Read(buf[:])
}()
// Give the goroutine a chance to enter the read.
// It doesn't matter much if it occasionally fails to do so,
// we won't be testing what we want to test but the test will pass.
time.Sleep(time.Millisecond)
c := make(chan bool)
go func() {
defer close(c)
f.Close()
}()
select {
case <-c:
case <-time.After(time.Second):
t.Error("timed out waiting for close")
}
// On some systems the goroutines may now be hanging.
// There's not much we can do about that.
}