Skip to content
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

[CORE-2814]: utils/file_io: fix double closing of ss::file in write_fully #18303

Merged

Commits on May 8, 2024

  1. 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.
    andijcr committed May 8, 2024
    Configuration menu
    Copy the full SHA
    d83a6cf View commit details
    Browse the repository at this point in the history