diff --git a/src/jamidht/multiplexed_socket.cpp b/src/jamidht/multiplexed_socket.cpp
index e8cde3f02fc28008208a2d995a2b7fb97a94b2ef..946b39d5dc49d739a0d28d88605a5d4d9f36cbe4 100644
--- a/src/jamidht/multiplexed_socket.cpp
+++ b/src/jamidht/multiplexed_socket.cpp
@@ -51,7 +51,15 @@ public:
     }) } { }
 
     ~Impl() {
-        shutdown();
+        if (!isShutdown_) {
+            shutdown();
+        } else {
+            std::lock_guard<std::mutex> lkSockets(socketsMutex);
+            for (auto& socket : sockets) {
+                if (socket.second) socket.second->stop();
+            }
+            sockets.clear();
+        }
     }
 
     void shutdown() {
@@ -68,6 +76,7 @@ public:
                 // No need to write the EOF for the channel, the write will fail because endpoint is already shutdown
                 if (socket.second) socket.second->stop();
             }
+            sockets.clear();
         }
     }