Skip to content

Commit 9d3b902

Browse files
committed
fix crash when signal interrupts polling
1 parent 597167c commit 9d3b902

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

c_src/erlzmq_nif.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,25 @@ static void * polling_thread(void * handle)
911911
for (;;) {
912912
int count = zmq_poll(vector_p(zmq_pollitem_t, &items_zmq),
913913
vector_count(&items_zmq), -1);
914-
assert(count != -1);
914+
if (count == -1) {
915+
int error = zmq_errno();
916+
if (error == EINTR) {
917+
// The operation was interrupted by delivery of a signal before any events were available
918+
continue;
919+
} else if (error == ETERM) {
920+
// At least one of the members of the items array refers to a socket whose associated ØMQ context was terminated.
921+
break;
922+
} else if (error == EFAULT) {
923+
fprintf(stderr, "invalid items providet to zmq_poll\n");
924+
assert(0);
925+
break;
926+
} else {
927+
fprintf(stderr, "unexpected error %d returned by zmq_poll\n", error);
928+
assert(0);
929+
break;
930+
}
931+
}
932+
915933
if (vector_get(zmq_pollitem_t, &items_zmq, 0)->revents & ZMQ_POLLIN) {
916934
--count;
917935
}
@@ -1229,6 +1247,13 @@ static void * polling_thread(void * handle)
12291247
}
12301248
}
12311249
}
1250+
1251+
vector_destroy(&requests);
1252+
vector_destroy(&items_zmq);
1253+
1254+
zmq_disconnect(thread_socket, context->thread_socket_name);
1255+
1256+
12321257
return NULL;
12331258
}
12341259

0 commit comments

Comments
 (0)