From 62f0b2ff24742352ac7ebde0df0d306fb6bb935e Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Wed, 7 May 2025 14:28:27 +0100 Subject: [PATCH 1/2] put service discovery zmq polls in try/catch as sending signals to parent application will make these crash the application otherwise --- src/ServiceDiscovery/ServiceDiscovery.cpp | 60 ++++++++++++++++++----- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/ServiceDiscovery/ServiceDiscovery.cpp b/src/ServiceDiscovery/ServiceDiscovery.cpp index 5ea9601..2ccdd07 100644 --- a/src/ServiceDiscovery/ServiceDiscovery.cpp +++ b/src/ServiceDiscovery/ServiceDiscovery.cpp @@ -123,7 +123,13 @@ void* ServiceDiscovery::MulticastPublishThread(void* arg){ while(running){ - zmq::poll(&items [0], 2, 1000); + try{ + zmq::poll(&items [0], 2, 1000); + } catch(zmq::error_t& err){ + // ignore poll aborting due to signals + if(zmq_errno()==EINTR) continue; + throw; + } if ((items [0].revents & ZMQ_POLLIN) && running) { @@ -252,15 +258,27 @@ void* ServiceDiscovery::MulticastPublishThread(void* arg){ zmq::message_t Esend(command.length()+1); snprintf ((char *) Esend.data(), command.length()+1 , "%s" ,command.c_str()) ; - - zmq::poll(out,1,1000); - + + try{ + zmq::poll(out,1,1000); + } catch(zmq::error_t& err){ + // ignore poll aborting due to signals + if(zmq_errno()==EINTR) continue; + throw; + } + if(out[0].revents & ZMQ_POLLOUT){ StatusCheck.send(Esend); - //std::cout<<"waiting for message "<second)>>service; zmq::message_t send(service.length()+1); snprintf ((char *) send.data(), service.length()+1 , "%s" ,service.c_str()) ; - - zmq::poll(out,1,1000); + + try{ + zmq::poll(out,1,1000); + } catch(zmq::error_t& err){ + // ignore poll aborting due to signals + if(zmq_errno()==EINTR) continue; + throw; + } if(out[0].revents & ZMQ_POLLOUT) Ireceive.send(send); } @@ -669,9 +699,15 @@ void* ServiceDiscovery::MulticastListenThread(void* arg){ *(it->second)>>service; zmq::message_t send(service.length()+1); snprintf ((char *) send.data(), service.length()+1 , "%s" ,service.c_str()) ; - - zmq::poll(out,1,1000); - + + try{ + zmq::poll(out,1,1000); + } catch(zmq::error_t& err){ + // ignore poll aborting due to signals + if(zmq_errno()==EINTR) continue; + throw; + } + if(out[0].revents & ZMQ_POLLOUT) Ireceive.send(send); } } From e300b2399f8f3aef35ee484576fa71437f1962ca Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Wed, 7 May 2025 14:31:38 +0100 Subject: [PATCH 2/2] bugfix; middleman version response no longer has quotes --- src/ServiceDiscovery/Services.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceDiscovery/Services.cpp b/src/ServiceDiscovery/Services.cpp index d7c4fd6..73dfba9 100644 --- a/src/ServiceDiscovery/Services.cpp +++ b/src/ServiceDiscovery/Services.cpp @@ -604,8 +604,8 @@ bool Services::SendPersistentROOTplot(const std::string& plot_name, const std::s } // response is json with the version number of the created plot entry - // e.g. '{"version":"3"}'. check this is what we got, as validation. - if(response.length()>14){ + // e.g. '{"version":3}'. check this is what we got, as validation. + if(response.length()>12){ // FIXME change to Store parsing so we can check this is the right key response.replace(0,response.find_first_of(':')+1,""); response.replace(response.find_last_of('}'),std::string::npos,"");