Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils/file_io: fix double closing of ss::file in write_fully
ss::output_stream internally keeps track of in-flight exceptions. In the close() method, it will close the underlying ss::file and rethrow the exception. ss::with_file_close_on_failure will too close the underlying ss::file if the future fails, this can result in a double close triggering an assertion like ``` seastar-prefix/src/seastar/include/seastar/core/future.hh:1917: future<T> seastar::promise<>::get_future() [T = void]: Assertion `!this->_future && this->_state && !this->_task' failed ``` This unit test shows how this assert could be triggered, if ss::output_stream as an active exception: ``` SEASTAR_THREAD_TEST_CASE(test_with_file_close_on_failure) { auto flags = ss::open_flags::rw | ss::open_flags::create | ss::open_flags::truncate; ss::with_file_close_on_failure( ss::open_file_dma("/tmp/tmp.YuupbuphlR", flags), [](ss::file f) mutable { return f.close().then([] { throw "any value"; }); }) .get(); } ``` This commit moves out ss::output_stream::close() from ss::with_file_close_on_failure. The method is coroutinized for clarity. (cherry picked from commit d83a6cf)
- Loading branch information