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;
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();
}
}
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)