0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00

Fix zmq crash when calling shutdown with a pending inproc socket connect

This commit is contained in:
Richard Newton 2015-08-21 10:06:54 +01:00
parent 4e5843b8ff
commit 096007c574
2 changed files with 29 additions and 2 deletions

View File

@ -126,15 +126,20 @@ zmq::ctx_t::~ctx_t ()
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;
for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) {
zmq::socket_base_t *s = create_socket (ZMQ_PAIR);
s->bind (p->first.c_str ());
s->close ();
}
terminating = saveTerminating;
slot_sync.lock ();
if (!starting) {
#ifdef HAVE_FORK

View File

@ -471,6 +471,27 @@ void test_unbind ()
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)
{
setup_test_environment ();
@ -484,6 +505,7 @@ int main (void)
test_identity ();
test_connect_only ();
test_unbind ();
test_shutdown_during_pend ();
return 0;
}