From 336f72720a99195942ced5c6aad2bb8e0baa3f32 Mon Sep 17 00:00:00 2001 From: Ian Barber Date: Tue, 5 Jun 2012 21:44:23 +0100 Subject: [PATCH] The previous code to block the socket from receiving on that pipe during a disconnect was vulnerable to a race condition. This code calls with the terminate functions of both ends of the pipe - I believe this should be safer. This required storing a pointer to the socket end of the pipe --- src/session_base.cpp | 6 ++++-- src/session_base.hpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/session_base.cpp b/src/session_base.cpp index cd4e0c3c..6acaa39c 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -308,6 +308,9 @@ void zmq::session_base_t::process_attach (i_engine *engine_) // Ask socket to plug into the remote end of the pipe. send_bind (socket, pipes [1]); + + // Store the outpipe for disconnect situations + outpipe = pipes [1]; } // Plug in the engine. @@ -411,8 +414,7 @@ void zmq::session_base_t::detached () if (pipe && options.delay_attach_on_connect == 1 && addr->protocol != "pgm" && addr->protocol != "epgm") { pipe->terminate (false); - socket->terminated (pipe); - pipe = NULL; + outpipe->terminate (false); } } diff --git a/src/session_base.hpp b/src/session_base.hpp index 8244cb59..02b68462 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -103,6 +103,9 @@ namespace zmq // Pipe connecting the session to its socket. zmq::pipe_t *pipe; + + // Socket end of the pipe, for delay attach scenario + zmq::pipe_t *outpipe; // This flag is true if the remainder of the message being processed // is still in the in pipe.