#3676·seastar

Possibility of a double-close error in `file_demo.cc` ?

Author: niekboumanCreated Sep 9, 2026Updated Sep 10, 2026

Dear Seastar devs, (+ @denesb )

in file_demo.cc, there is the following pattern:

cpp
       // with_file_close_on_failure will close the opened file only if
       // `make_file_output_stream` returns an error. Otherwise, in the error-free path,
       // the opened file is moved to `file_output_stream` that in-turn closes it
       // when the stream is closed.
       auto make_output_stream = [] (std::string_view filename) {
           return with_file_close_on_failure(open_file_dma(filename, open_flags::rw | open_flags::create), [] (file f) {
               return make_file_output_stream(std::move(f), aligned_size);
           });
       };

However, in commit https://github.com/scylladb/seastar/commit/52e0a763e877fa86f896ffee27e2872661d91049 , there was a change to make_file_output_stream so that it will close the file upon failure itself.

Could there occur a double-close error in the file_demo.cc example if an exception occurs in the quoted pattern?

Note: I have not seen this error actually happen, but I wonder about this possibility from reading the code.