Commit b07b1e27 authored by Constantin Rack's avatar Constantin Rack

Merge pull request #1545 from ricnewton/master

Fix zmq crash when calling shutdown with a pending inproc socket connect
parents 4e5843b8 096007c5
...@@ -126,15 +126,20 @@ zmq::ctx_t::~ctx_t () ...@@ -126,15 +126,20 @@ zmq::ctx_t::~ctx_t ()
int zmq::ctx_t::terminate () int zmq::ctx_t::terminate ()
{ {
// Connect up any pending inproc connections, otherwise we will hang slot_sync.lock();
bool saveTerminating = terminating;
terminating = false;
// Connect up any pending inproc connections, otherwise we will hang
pending_connections_t copy = pending_connections; pending_connections_t copy = pending_connections;
for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) { for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) {
zmq::socket_base_t *s = create_socket (ZMQ_PAIR); zmq::socket_base_t *s = create_socket (ZMQ_PAIR);
s->bind (p->first.c_str ()); s->bind (p->first.c_str ());
s->close (); s->close ();
} }
terminating = saveTerminating;
slot_sync.lock ();
if (!starting) { if (!starting) {
#ifdef HAVE_FORK #ifdef HAVE_FORK
......
...@@ -471,6 +471,27 @@ void test_unbind () ...@@ -471,6 +471,27 @@ void test_unbind ()
assert (rc == 0); assert (rc == 0);
} }
void test_shutdown_during_pend ()
{
void *ctx = zmq_ctx_new ();
assert (ctx);
// Connect first
void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);
assert (connectSocket);
int rc = zmq_connect (connectSocket, "inproc://cbb");
assert (rc == 0);
zmq_ctx_shutdown (ctx);
// Cleanup
rc = zmq_close (connectSocket);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
}
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
...@@ -484,6 +505,7 @@ int main (void) ...@@ -484,6 +505,7 @@ int main (void)
test_identity (); test_identity ();
test_connect_only (); test_connect_only ();
test_unbind (); test_unbind ();
test_shutdown_during_pend ();
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment