Skip to content

Commit

Permalink
fix crash when signal interrupts polling
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed May 6, 2020
1 parent 597167c commit 9d3b902
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion c_src/erlzmq_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,25 @@ static void * polling_thread(void * handle)
for (;;) {
int count = zmq_poll(vector_p(zmq_pollitem_t, &items_zmq),
vector_count(&items_zmq), -1);
assert(count != -1);
if (count == -1) {
int error = zmq_errno();
if (error == EINTR) {
// The operation was interrupted by delivery of a signal before any events were available
continue;
} else if (error == ETERM) {
// At least one of the members of the items array refers to a socket whose associated ØMQ context was terminated.
break;
} else if (error == EFAULT) {
fprintf(stderr, "invalid items providet to zmq_poll\n");
assert(0);
break;
} else {
fprintf(stderr, "unexpected error %d returned by zmq_poll\n", error);
assert(0);
break;
}
}

if (vector_get(zmq_pollitem_t, &items_zmq, 0)->revents & ZMQ_POLLIN) {
--count;
}
Expand Down Expand Up @@ -1229,6 +1247,13 @@ static void * polling_thread(void * handle)
}
}
}

vector_destroy(&requests);
vector_destroy(&items_zmq);

zmq_disconnect(thread_socket, context->thread_socket_name);


return NULL;
}

Expand Down

0 comments on commit 9d3b902

Please sign in to comment.