mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
Merge pull request #1545 from ricnewton/master
Fix zmq crash when calling shutdown with a pending inproc socket connect
This commit is contained in:
commit
b07b1e270e
@ -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 ()
|
|||||||
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)
|
|||||||
test_identity ();
|
test_identity ();
|
||||||
test_connect_only ();
|
test_connect_only ();
|
||||||
test_unbind ();
|
test_unbind ();
|
||||||
|
test_shutdown_during_pend ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user