Closed zwade closed 2 years ago
Thanks for the report!
You're correct, a very short timeout may result in blocking operation. Even if theoretical (we are talking about timeout of less than microseconds) I'll prepare a patch for this one.
Thanks for taking a look at this! The PR looks good to me, hopefully the maintainers can take a look soon.
When computing the timeouts for the
select
syscall on unix/linux, the code first addstime.Now()
to the user-provided timeout, then at a later point subtractstime.Now()
. However, since these are two different timestamps, it means that the value that gets passed to the syscall can be negative if the user supplies a sufficiently small timeout. (c.f. https://github.com/bugst/go-serial/blob/master/serial_unix.go#L75)In theory this should raise
EINVAL
which would at least get propagated up the stack, but in my testing it seems that the function never returns. I haven't tracked down why, but my suspicion is that something is casting theint
to auint
.Ideally the timeout value would get passed directly to the syscall unchanged, but I think it's probably more important to make sure that the function always returns.
Thanks!
(Details: go: 17, go-serial: 1.3.4, os: Ubuntu 20.04.3)