From 9d31965548b5c734f1edc01742c39f984e9cedd8 Mon Sep 17 00:00:00 2001 From: James Harvey Date: Tue, 10 Oct 2023 14:46:48 +0100 Subject: [PATCH] Handle tcp self connection issues (#4599) --- src/endpoint.hpp | 2 ++ src/stream_engine_base.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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);