diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 68cfb54fc2..c23cdc862b 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -1056,9 +1056,26 @@ void sstable::write_simple(const T& component, const io_priority_class& pc) { options.buffer_size = sstable_buffer_size; options.io_priority_class = pc; auto w = file_writer(std::move(f), std::move(options)); - write(_version, w, component); - w.flush(); - w.close(); + std::exception_ptr eptr; + try { + write(_version, w, component); + w.flush(); + } catch (...) { + eptr = std::current_exception(); + } + try { + w.close(); + } catch (...) { + std::exception_ptr close_eptr = std::current_exception(); + sstlog.warn("failed to close file_writer: {}", close_eptr); + // If write succeeded but close failed, we rethrow close's exception. + if (!eptr) { + eptr = close_eptr; + } + } + if (eptr) { + std::rethrow_exception(eptr); + } } template future<> sstable::read_simple(sstables::filter& f, const io_priority_class& pc);