From 1b12622540e11f6f8547f5af5cc5db67890cad2e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 24 May 2018 17:35:39 +0200 Subject: [PATCH] dnsdist: Don't reconnect the socket on healthcheck failure --- pdns/dnsdist.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index aeec6f39b..73b013655 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1077,7 +1077,7 @@ bool processResponse(LocalStateHolder >& local return true; } -static ssize_t udpClientSendRequestToBackend(DownstreamState* ss, const int sd, const char* request, const size_t requestLen) +static ssize_t udpClientSendRequestToBackend(DownstreamState* ss, const int sd, const char* request, const size_t requestLen, bool healthCheck=false) { ssize_t result; @@ -1098,8 +1098,11 @@ static ssize_t udpClientSendRequestToBackend(DownstreamState* ss, const int sd, vinfolog("Error sending request to backend %s: %d", ss->remote.toStringWithPort(), savederrno); /* This might sound silly, but on Linux send() might fail with EINVAL - if the interface the socket was bound to doesn't exist anymore. */ - if (savederrno == EINVAL) { + if the interface the socket was bound to doesn't exist anymore. + We don't want to reconnect the real socket if the healthcheck failed, + because it's not using the same socket. + */ + if (!healthCheck && (savederrno == EINVAL || savederrno == ENODEV)) { ss->reconnect(); } } @@ -1679,7 +1682,7 @@ try sock.bind(ds.sourceAddr); } sock.connect(ds.remote); - ssize_t sent = udpClientSendRequestToBackend(&ds, sock.getHandle(), (char*)&packet[0], packet.size()); + ssize_t sent = udpClientSendRequestToBackend(&ds, sock.getHandle(), (char*)&packet[0], packet.size(), true); if (sent < 0) { int ret = errno; if (g_verboseHealthChecks) -- 2.40.0