Skip to content

Commit 771dcdd

Browse files
committed
DPL: do own management of shared memory
We do not spawn a shm-monitor because that will create zombies when launched inside a docker container. Instead by default we cleanup the shared memory session on exit. Default behavior can still be obtained by passing --shm-monitor true.
1 parent f9b671e commit 771dcdd

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

Framework/Core/src/DeviceSpecHelpers.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
801801
std::vector<std::string> tmpArgs = {argv[0],
802802
"--id", spec.id.c_str(),
803803
"--control", "static",
804+
"--shm-monitor", "false",
804805
"--log-color", "false",
805806
"--color", "false"};
806807
if (defaultStopped) {
@@ -850,6 +851,7 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
850851
realOdesc.add_options()("child-driver", bpo::value<std::string>());
851852
realOdesc.add_options()("rate", bpo::value<std::string>());
852853
realOdesc.add_options()("shm-segment-size", bpo::value<std::string>());
854+
realOdesc.add_options()("shm-monitor", bpo::value<std::string>());
853855
realOdesc.add_options()("session", bpo::value<std::string>());
854856
filterArgsFct(expansions.we_wordc, expansions.we_wordv, realOdesc);
855857
wordfree(&expansions);
@@ -949,6 +951,7 @@ boost::program_options::options_description DeviceSpecHelpers::getForwardedDevic
949951
("plugin-search-path,S", bpo::value<std::string>(), "FairMQ plugins search path") //
950952
("control-port", bpo::value<std::string>(), "Utility port to be used by O2 Control") //
951953
("rate", bpo::value<std::string>(), "rate for a data source device (Hz)") //
954+
("shm-monitor", bpo::value<std::string>(), "whether to use the shared memory monitor") //
952955
("shm-segment-size", bpo::value<std::string>(), "size of the shared memory segment in bytes") //
953956
("session", bpo::value<std::string>(), "unique label for the shared memory session") //
954957
("monitoring-backend", bpo::value<std::string>(), "monitoring connection string") //

Framework/Core/src/runDataProcessing.cxx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ static void handle_sigint(int)
273273
}
274274
}
275275

276+
/// Helper to invoke shared memory cleanup
277+
void cleanupSHM(std::string const& uniqueWorkflowId)
278+
{
279+
auto shmCleanup = fmt::format("fairmq-shmmonitor --cleanup -s dpl_{} 2>&1 >/dev/null", uniqueWorkflowId);
280+
LOG(debug)
281+
<< "Cleaning up shm memory session with " << shmCleanup;
282+
auto result = system(shmCleanup.c_str());
283+
if (result != 0) {
284+
LOG(error) << "Unable to cleanup shared memory, run " << shmCleanup << "by hand to fix";
285+
}
286+
}
287+
276288
static void handle_sigchld(int) { sigchld_requested = true; }
277289

278290
void spawnRemoteDevice(std::string const& forwardedStdin,
@@ -848,6 +860,9 @@ int runStateMachine(DataProcessorSpecs const& workflow,
848860
}
849861
FD_ZERO(&(driverInfo.childFdset));
850862

863+
/// Cleanup the shared memory for the uniqueWorkflowId, in
864+
/// case we are unlucky and an old one is already present.
865+
cleanupSHM(driverInfo.uniqueWorkflowId);
851866
/// After INIT we go into RUNNING and eventually to SCHEDULE from
852867
/// there and back into running. This is because the general case
853868
/// would be that we start an application and then we wait for
@@ -1057,8 +1072,10 @@ int runStateMachine(DataProcessorSpecs const& workflow,
10571072
driverInfo.states.push_back(DriverState::GUI);
10581073
}
10591074
break;
1060-
case DriverState::EXIT:
1075+
case DriverState::EXIT: {
1076+
cleanupSHM(driverInfo.uniqueWorkflowId);
10611077
return calculateExitCode(infos);
1078+
}
10621079
case DriverState::PERFORM_CALLBACKS:
10631080
for (auto& callback : driverControl.callbacks) {
10641081
callback(workflow, deviceSpecs, deviceExecutions, dataProcessorInfos);

Framework/Core/test/test_FrameworkDataFlowToDDS.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ BOOST_AUTO_TEST_CASE(TestDDS)
9797
dumpDeviceSpec2DDS(ss, devices, executions);
9898
BOOST_CHECK_EQUAL(ss.str(), R"EXPECTED(<topology id="o2-dataflow">
9999
<decltask id="A">
100-
<exe reachable="true">foo --id A --control static --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
100+
<exe reachable="true">foo --id A --control static --shm-monitor false --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
101101
</decltask>
102102
<decltask id="B">
103-
<exe reachable="true">foo --id B --control static --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
103+
<exe reachable="true">foo --id B --control static --shm-monitor false --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
104104
</decltask>
105105
<decltask id="C">
106-
<exe reachable="true">foo --id C --control static --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
106+
<exe reachable="true">foo --id C --control static --shm-monitor false --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
107107
</decltask>
108108
<decltask id="D">
109-
<exe reachable="true">foo --id D --control static --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
109+
<exe reachable="true">foo --id D --control static --shm-monitor false --log-color false --color false --jobs 4 --session dpl_workflow-id --plugin-search-path $FAIRMQ_ROOT/lib --plugin dds</exe>
110110
</decltask>
111111
<declcollection name="DPL">
112112
<tasks>

0 commit comments

Comments
 (0)