Opened 11 years ago

Closed 10 years ago

#6576 closed Bugs (fixed)

boost:::iostreams::file_descriptor throws instead of reading EOF on pipe

Reported by: maihem@… Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.48.0 Severity: Problem
Keywords: pipe read ReadFile CreatePipe Cc: maihem@…

Description

when using file_descriptor to read from a pipe on windows, an exception can be thrown if the write-side has broken the pipe - eg by exiting if it's another process.

This is how I used the read-side of the pipe to trigger the failure (if you need a complete minimal sample including windows pipe and process handling code, please ask). I just used CreateProcess to start a cmd.exe shell script that echo'd a couple of lines to stdout. The pipe has less than the default buffer size written before the write side is closed:

file_descriptor fd(pipe_read_side_handle); newline_filter nl(newline::posix); filtered_istream fs; fs.push(nl); fs.push(fd); string str; getline(fs, str);

fs.good() is now false

expected: fs.good() should be true here getline(fs, str); getline(fs, str); ... eventually fs.eof() should be true getline(fs, str); one more getline then fs.fail() should be true. I think there are a few different behaviours depending on whether there is a trailing newline or not but I think fs.badbit should not be set

Attachments (3)

file_descriptor.cpp (20.3 KB ) - added by anonymous 11 years ago.
fixed version of file_descriptor.cpp
test1.cpp (783 bytes ) - added by boris@… 10 years ago.
Throws when read-end is closed
test2.cpp (856 bytes ) - added by boris@… 10 years ago.
Returns 0 instead of -1 when write-end is closed

Download all attachments as: .zip

Change History (6)

by anonymous, 11 years ago

Attachment: file_descriptor.cpp added

fixed version of file_descriptor.cpp

by boris@…, 10 years ago

Attachment: test1.cpp added

Throws when read-end is closed

by boris@…, 10 years ago

Attachment: test2.cpp added

Returns 0 instead of -1 when write-end is closed

comment:1 by boris@…, 10 years ago

I can confirm the bug (tested with Boost 1.50.0). I can also confirm that the proposed bug fix works (file_descriptor_impl::read should return -1 when GetLastError returns ERROR_BROKEN_PIPE). I've attached two test programs which can be used to reproduce the problem and to test a possible fix.

comment:2 by Marshall Clow, 10 years ago

(In [79919]) Fix throwing error; Refs #6576

comment:3 by Marshall Clow, 10 years ago

Resolution: fixed
Status: newclosed

(In [79970]) Merging to release; Fixes #6576

Note: See TracTickets for help on using tickets.