-
Notifications
You must be signed in to change notification settings - Fork 127
Description
I was expecting Read to be interrupted by Close, but this doesn't work.
The issue is that in blocking mode, the read is not interrupted even if the file is closed until the vmin or vtime condition is satisfied, and because I use vmin > 0 and vtime > 0, Read would never return.
The solution is to put it into non-blocking mode. In this case, read returns EAGAIN, and the go epoll implementation will properly wait for data to be available: https://github.com/golang/go/blob/release-branch.go1.12/src/internal/poll/fd_unix.go#L168
Just removing this isn't enough, because Fd puts it into blocking mode: https://github.com/golang/go/blob/release-branch.go1.12/src/os/file_unix.go#L70
So I removed the first SetNonblock call and added syscall.SetNonblock(int(file.Fd()), true) to the end of openInternal in open_linux.go. This works fine in my testing.