diff --git a/src/endpoint.hpp b/src/endpoint.hpp index c19b6feae9..8727ae5c44 100644 --- a/src/endpoint.hpp +++ b/src/endpoint.hpp @@ -29,6 +29,8 @@ struct endpoint_uri_pair_t return local_type == endpoint_type_bind ? local : remote; } + const bool clash () const { return local == remote; } + std::string local, remote; endpoint_type_t local_type; }; diff --git a/src/stream_engine_base.cpp b/src/stream_engine_base.cpp index 71e09b1ba0..132c85d70d 100644 --- a/src/stream_engine_base.cpp +++ b/src/stream_engine_base.cpp @@ -294,8 +294,14 @@ bool zmq::stream_engine_base_t::in_event_internal () // or the session has rejected the message. if (rc == -1) { if (errno != EAGAIN) { - error (protocol_error); - return false; + // In cases where the src/dst have the same IP and the dst uses an ephemeral port, reconnection + // eventually results in the src and dest IP and port clashing (google tcp self connection) + // While this is a protocol_error (you have the single zmq socket handshaking with itself) + // we do not want to to stop reconnection from happening + if (!_endpoint_uri_pair.clash ()) { + error (protocol_error); + return false; + } } _input_stopped = true; reset_pollin (_handle);