Skip to content

Commit 5dc7c32

Browse files
committed
Fix segfault in primary server device upon termination signal
Apparently the Run function continues after a signal was received which lead to an interrupt in the ZMQ Receive function. Now detecting this situation and initiating clean shutdown ourselfs. Fixes https://alice.its.cern.ch/jira/browse/O2-2367
1 parent 23dc96d commit 5dc7c32

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

run/O2PrimaryServerDevice.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,24 @@ class O2PrimaryServerDevice final : public FairMQDevice
336336
PrimaryChunkRequest requestpayload;
337337
std::unique_ptr<FairMQMessage> request(channel.NewSimpleMessage(requestpayload));
338338
auto bytes = channel.Receive(request);
339-
340-
auto& r = *((PrimaryChunkRequest*)(request->GetData()));
341-
LOG(INFO) << "PARTICLE REQUEST IN STATE " << PrimStateToString[(int)mState.load()] << " from " << r.workerid << ":" << r.requestid;
339+
if (bytes < 0) {
340+
LOG(ERROR) << "Some error/interrupt occurred on socket during receive";
341+
// This may likely be due to an external signal which disrupts the polling
342+
LOG(INFO) << "Get current state : " << GetCurrentStateName();
343+
LOG(INFO) << "New state pending : " << NewStatePending();
344+
if (NewStatePending()) { // new state is typically pending if (term) signal was received
345+
WaitForNextState();
346+
// ask ourselves for termination of this loop
347+
stateTransition(O2PrimaryServerState::Stopped, "CONDRUN");
348+
}
349+
continue;
350+
}
342351

343352
TStopwatch timer;
344353
timer.Start();
354+
auto& r = *((PrimaryChunkRequest*)(request->GetData()));
355+
LOG(INFO) << "PARTICLE REQUEST IN STATE " << PrimStateToString[(int)mState.load()] << " from " << r.workerid << ":" << r.requestid;
345356

346-
if (bytes < 0) {
347-
LOG(ERROR) << "Some error occurred on socket during receive";
348-
// return true; // keep going
349-
}
350357
auto prestate = mState.load();
351358
auto more = HandleRequest(request, 0, channel);
352359
if (!more) {

0 commit comments

Comments
 (0)