Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 975a4ee

Browse files
authored
Fix issue where unsubscribing in push_events led to API_EventTimeout … (#699)
Subscribing or unsubscribing events in an event callback when this callback was called during a subscribe_event() phase was leading to events and heartbeat events no longer received by the event client. A bug was fixed when several ZMQ_DELAY_EVENT commands were received consecutively by the ZMQ control socket. Stop delaying events only if there is no other ZMQ_DELAY_EVENT command currently requested
1 parent d02c52b commit 975a4ee

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

cppapi/client/zmqeventconsumer.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,9 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
698698
{
699699
bool ret = false;
700700

701+
// static variable to count the number of ZMQ_DELAY_EVENT requests currently in progress:
702+
static int nb_current_delay_event_requests = 0;
703+
701704
//
702705
// For debug and logging purposes
703706
//
@@ -1075,14 +1078,32 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
10751078

10761079
case ZMQ_DELAY_EVENT:
10771080
{
1078-
old_poll_nb = poll_nb;
1079-
poll_nb = 1;
1081+
// If poll_nb == 1, then we are already in a situation where events are being delayed
1082+
// and we are currently only taking care of messages received on the control socket
1083+
// No need to update old_poll_nb in this case because it is already correct
1084+
// otherwise this would lead to issues like https://github.com/tango-controls/cppTango/issues/686
1085+
// where events would no longer be received if someone subscribes or unsubscribes to events in
1086+
// an event callback and when the callback is executed during a subscribe_event call
1087+
if (poll_nb != 1)
1088+
{
1089+
old_poll_nb = poll_nb;
1090+
poll_nb = 1;
1091+
}
1092+
nb_current_delay_event_requests++;
10801093
}
10811094
break;
10821095

10831096
case ZMQ_RELEASE_EVENT:
10841097
{
1085-
poll_nb = old_poll_nb;
1098+
if(nb_current_delay_event_requests >= 1)
1099+
{
1100+
nb_current_delay_event_requests--;
1101+
}
1102+
if(nb_current_delay_event_requests == 0)
1103+
{
1104+
// Stop delaying events only if there is no other ZMQ_DELAY_EVENT command requested
1105+
poll_nb = old_poll_nb;
1106+
}
10861107
}
10871108
break;
10881109

0 commit comments

Comments
 (0)