From 876887dd7d250a9ac2fb3ffaa4eb1160681c2d1a Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 24 Apr 2020 12:45:45 +0200 Subject: [PATCH] dnsdist: Gracefully handle a failure to remove FD on (re)-connection When more than one socket per backend is used, we might not have added all the socket descriptors to the multiplexer and that's fine. --- pdns/dnsdistdist/dnsdist-backend.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index 606977c098..fbce5dd708 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -79,8 +79,14 @@ bool DownstreamState::reconnect() for (auto& fd : sockets) { if (fd != -1) { if (sockets.size() > 1) { - std::lock_guard lock(socketsLock); - mplexer->removeReadFD(fd); + try { + std::lock_guard lock(socketsLock); + mplexer->removeReadFD(fd); + } + catch (const FDMultiplexerException& e) { + /* some sockets might not have been added to the multiplexer + yet, that's fine */ + } } /* shutdown() is needed to wake up recv() in the responderThread */ shutdown(fd, SHUT_RDWR); -- 2.47.2