boostorg / boostorg/iostreams

No way to detect the return code of pubsync() during close()

Open
#170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
48
Forks
124
PR merge metrics
No merged PRs in 30d

Description

This program completes successfully despite the fact that it failed to write any data:

```
#include
#include
#include

int main() {
std::ofstream s{"/dev/full"};
boost::iostreams::filtering_ostream filtering{};
filtering.push(boost::iostreams::gzip_compressor{});
filtering.push(s);
filtering << "Hello, world!";
boost::iostreams::close(filtering);
// at this point, s.good() is true
}
```

Debugging reveals that inside of `close()`, a call to `pubsync()` has indicated an error flushing out the data. This error is noticed by `boost::iostreams`'s `flush` implementation (`flush.hpp:65`):

```
template<>
struct flush_device_impl {
template
static bool flush(T& t)
{ return t.rdbuf()->BOOST_IOSTREAMS_PUBSYNC() == 0; }
};
```

But `flush`'s result is ignored inside of the `close()` implementation (`close.hpp:170`):

```
template
static void close(T& t, BOOST_IOS::openmode which)
{
if (which == BOOST_IOS::out)
iostreams::flush(t);
}
```

Since the compressing filters are not flushable, the only way to flush them is to close them; since this error is ignored on close, there appears to be no way in the API to discover this form of write failure when a compressing filter is in the chain.

There should be a way to avoid ignoring this error. Maybe `close` should throw if the call to `iostreams::flush` fails.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with close.hpp:170 and flush.hpp:65, then reproduce the failure using the provided /dev/full program and the boost::iostreams::close entry point. Done means the pubsync() failure during close is no longer silently ignored and can be discovered through the API.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.