]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Gracefully handle a failure to remove FD on (re)-connection 9057/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 24 Apr 2020 10:45:45 +0000 (12:45 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 24 Apr 2020 10:45:45 +0000 (12:45 +0200)
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

index 606977c098fe4c8c3b93e242165fd6c234b46ca8..fbce5dd708350464b63941ef0963cb68ab406d6a 100644 (file)
@@ -79,8 +79,14 @@ bool DownstreamState::reconnect()
     for (auto& fd : sockets) {
       if (fd != -1) {
         if (sockets.size() > 1) {
-          std::lock_guard<std::mutex> lock(socketsLock);
-          mplexer->removeReadFD(fd);
+          try {
+            std::lock_guard<std::mutex> 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);