diff --git a/src/multiplexed_socket.cpp b/src/multiplexed_socket.cpp
index 8dbf78657a3fc5f9e7dc542903736dd22958b9e8..3a130d9ad7861525501b0e2df4e3065ddf2393e2 100644
--- a/src/multiplexed_socket.cpp
+++ b/src/multiplexed_socket.cpp
@@ -284,19 +284,21 @@ MultiplexedSocket::Impl::eventLoop()
 void
 MultiplexedSocket::Impl::onAccept(const std::string& name, uint16_t channel)
 {
-    std::lock_guard lkSockets(socketsMutex);
-    auto& socket = sockets[channel];
+    std::unique_lock lk(socketsMutex);
+    auto socket = sockets[channel];
     if (!socket) {
         if (logger_)
             logger_->error("Receiving an answer for a non existing channel. This is a bug.");
         return;
     }
 
+    lk.unlock();
     onChannelReady_(deviceId, socket);
     socket->ready(true);
     // Due to the callbacks that can take some time, onAccept can arrive after
     // receiving all the data. In this case, the socket should be removed here
     // as handle by onChannelReady_
+    lk.lock();
     if (socket->isRemovable())
         sockets.erase(channel);
     else