Should io.PipeWriter.Write block when writing zero bytes?

159 views
Skip to first unread message

Jon

unread,
Jan 28, 2016, 4:30:03 PM1/28/16
to golang-nuts
The writers from ioutil.TempFile and net.Dial don't seem to block when calling Write([]byte{}) on them. Instead they return immediately indicating they have written zero bytes.

Should io.PipeWriter.Write follow the same behaviour for consistency? Note that the io.Pipe unblocks if you io.PipeReader.Read from the other end.

http://play.golang.org/p/MNSyKafKYf

Andrew Gerrand

unread,
Jan 28, 2016, 5:24:10 PM1/28/16
to Jon, golang-nuts
The documentation for the io.PipeWriter's Write method says:

Write implements the standard Write interface: it writes data to the pipe, blocking until readers have consumed all the data or the read end is closed. If the read end is closed with an error, that err is returned as err; otherwise err is ErrClosedPipe.

Note "blocking until readers have consumed all the data." I think it's reasonable to assume that if there's no data, the write should not block. I also doubt that changing this behavior will negatively affect existing users of io.Pipe. Would you mind filing an issue suggesting the change?

Thanks,
Andrew

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon

unread,
Jan 28, 2016, 5:36:05 PM1/28/16
to golang-nuts, jonathan...@gmail.com
Thanks for the response Andrew. The issue is filed here:

Reply all
Reply to author
Forward
0 new messages