Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle startup conditions for fifos.
When opening a fifo in nonblocking mode to allow for delays in the writer, we also turn the Read into a nonblocking read. This is desirable for context cancellation but makes the Read return before bytes may be ready. `pipe(7)` and `read(2)` POSIX manpages tell us that if there are no writers connected, `read` will return end-of-file. In Go, this means we get a (0, EOF) pair. We shouldn't necessarily exit straight away though, because the writer may not have started writing yet. In test this is visible as race conditions when the `Read` is scheduled before the test performs a `Write`. We can decide that a stream is active once a single byte has been read, and only allow EOF to trigger shutdown on an active stream. Thus we check here for `total > 0` for 0 byte and EOF err responses on `Read` before exiting the stream. This fixes known races in `pipestream` so far.
- Loading branch information