-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: PipeWriter.Write should not block when writing zero bytes #14139
Comments
What's the behavior of network or stdio paired writes when there are no corresponding blocking readers? I figure it should emulate that behavior, whatever it is. |
There are uses for zero-byte writes, exactly to see whether there are readers, but since nothing is documented it seems unlikely that anybody is relying on it. Whatever we decide, we should document the behavior. |
io.Pipe preserves message boundaries. Writes and Reads are paired one to one (except when it requires multiple Reads to consume a single Write). Write should block when writing zero bytes, until a Read comes along and takes them. |
We have so many random rules for 0 byte reads & writes. I'll add this to my mental list of special cases. This might be fine behavior for a PipeFoo but it'd be really nice to define semantics for 0-byte operations on the io.Reader and io.Writer interfaces. |
@rsc Does that make this WAI? Or should we repurpose this issue to improve the documentation? |
Yes, it sounds like documentation. |
CL https://golang.org/cl/31321 mentions this issue. |
io.PipeWriter.Write([]byte{})
blocks when no readers are waiting at the other end of the pipe. To unblock the pipe zero or more bytes must be read fromio.PipeWriter.Read
.I expect
io.PipeWriter.Write([]byte{})
to not ever block.See https://groups.google.com/forum/#!topic/golang-nuts/nRPhBt0zoAM for the discussion.
See http://play.golang.org/p/MNSyKafKYf for an example.
The text was updated successfully, but these errors were encountered: