Merge pull request #136 from cmaglie/fix_small_timeout

Fix potential small timeout bug on unix implementation
This commit is contained in:
Cristian Maglie
2022-02-21 16:04:00 +01:00
committed by GitHub

View File

@@ -72,7 +72,11 @@ func (port *unixPort) Read(p []byte) (int, error) {
for { for {
timeout := time.Duration(-1) timeout := time.Duration(-1)
if port.readTimeout != NoTimeout { if port.readTimeout != NoTimeout {
timeout = deadline.Sub(time.Now()) timeout = time.Until(deadline)
if timeout < 0 {
// a negative timeout means "no-timeout" in Select(...)
timeout = 0
}
} }
res, err := unixutils.Select(fds, nil, fds, timeout) res, err := unixutils.Select(fds, nil, fds, timeout)
if err == unix.EINTR { if err == unix.EINTR {