image_pusher: reset writer when EndDataCollection finalization fails
HDF5FilePusher::EndDataCollection released the FileWriter only after writer->WriteHDF5()/Finalize(), both of which throw at rename time when a target file already exists and overwrite is off. The throw skipped writer.reset(), leaving 'writer' non-null so the next StartDataCollection died with "Image pusher is already writing images". Tear the writer down on every exit path (try/catch + rethrow) so a failed collection no longer blocks the next one. The error still propagates and the orphaned temp files are intentionally left on disk. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,16 +39,25 @@ void HDF5FilePusher::StartDataCollection(StartMessage &message) {
|
||||
}
|
||||
|
||||
bool HDF5FilePusher::EndDataCollection(const EndMessage &message) {
|
||||
if (writer_future.valid()) {
|
||||
writer_queue.PutBlocking({.end = true});
|
||||
writer_future.get();
|
||||
} else
|
||||
if (!writer_future.valid())
|
||||
throw JFJochException(JFJochExceptionCategory::WrongDAQState, "Image pusher wasn't writing files");
|
||||
|
||||
if (!writer)
|
||||
throw JFJochException(JFJochExceptionCategory::WrongDAQState, "Image pusher not ready for writing images");
|
||||
writer->WriteHDF5(message);
|
||||
writer->Finalize();
|
||||
writer_queue.PutBlocking({.end = true});
|
||||
|
||||
// Release the writer on every exit path. If finalization throws (e.g. a target
|
||||
// file already exists and overwrite is off) the writer must still be torn down,
|
||||
// otherwise the next collection fails with "already writing images".
|
||||
try {
|
||||
writer_future.get();
|
||||
|
||||
if (!writer)
|
||||
throw JFJochException(JFJochExceptionCategory::WrongDAQState, "Image pusher not ready for writing images");
|
||||
writer->WriteHDF5(message);
|
||||
writer->Finalize();
|
||||
} catch (...) {
|
||||
writer.reset();
|
||||
throw;
|
||||
}
|
||||
writer.reset();
|
||||
|
||||
if (repub_socket) {
|
||||
|
||||
Reference in New Issue
Block a user