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

[v24.1.x] [CORE-2814]: utils/file_io: fix double closing of ss::file in write_fully #18440

Conversation

vbotbuildovich
Copy link
Collaborator

Backport of PR #18303
Fixes: #18439,

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)
@vbotbuildovich vbotbuildovich added this to the v24.1.x-next milestone May 13, 2024
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label May 13, 2024
@piyushredpanda piyushredpanda merged commit 607753c into redpanda-data:v24.1.x May 23, 2024
18 checks passed
@piyushredpanda piyushredpanda modified the milestones: v24.1.x-next, v24.1.3 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redpanda kind/backport PRs targeting a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants