dev/fixed receiver deadlock bug in hdf5 file writing (#1675)

* fixed receiver deadlock bug in hdf5 file writing

* added test to check that rx_start fails (else hangs in previous case) for binary and hdf5 with incorrect permissions

---------

Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
Co-authored-by: AliceMazzoleni99 <alice.mazzoleni@psi.ch>
This commit is contained in:
authored and GitHub committed 2026-11-18 11:36:54 +01:00
1 parent 45d8648fdf
commit b7f2b3ac91
2 files changed
+33 -2

No files matched your search

@@ -8,11 +8,14 @@
#include "acquire/ExpectedState.h"
#include "acquire/FileState.h"
#include "checks/MasterFileChecks.h"
#include "tests/globals.h"
namespace sls {
namespace acq = sls::test::acquire;
namespace checks = sls::test::checks;
using test::GET;
using test::PUT;
void acquire_and_check_file_size(
Detector &det, std::optional<acq::CTBState> ctb_state = std::nullopt) {
@@ -270,4 +273,29 @@ TEST_CASE("acquire_check_binary_file_size",
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
}
TEST_CASE("rx_start_fails_fpath_permissions", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
// not needed to test for every detector type, just one is enough
if (det_type == defs::JUNGFRAU) {
std::vector<defs::fileFormat> formats{defs::BINARY};
#ifdef HDF5C
formats.push_back(defs::HDF5);
#endif
for (auto format : formats) {
INFO("File format: " << ToString(format));
auto file_state = acq::default_file_state();
file_state.file_format = format;
file_state.file_write = true;
// no write permission, rx_start fails later
file_state.file_path = "/";
acq::FileStateGuard file_guard(det, file_state);
REQUIRE_THROWS(caller.call("rx_start", {}, -1, PUT));
}
}
}
} // namespace sls
+5 -2
View File
@@ -136,7 +136,7 @@ void HDF5DataFile::CreateFile() {
'_' + std::to_string(fileIndex) + ".h5");
fileName = p.string();
std::lock_guard<std::mutex> lock(*hdf5Lib);
std::unique_lock<std::mutex> lock(*hdf5Lib);
uint64_t framestosave =
((maxFramesPerFile == 0) ? numImages : // infinite images
@@ -207,8 +207,11 @@ void HDF5DataFile::CreateFile() {
}
} catch (const H5::Exception &error) {
error.printErrorStack();
lock.unlock(); // CloseFile() also wants the mutex --> need to unlock
// here
CloseFile();
throw RuntimeError("Could not create HDF5 handles in object " + index);
throw RuntimeError("Could not create HDF5 handles in object " +
std::to_string(index));
}
if (!silentMode) {
LOG(logINFO) << "[" << udpPortNumber