diff --git a/src/Client/MultiplexedConnections.cpp b/src/Client/MultiplexedConnections.cpp index c4c5010df342..3b1a09631dd9 100644 --- a/src/Client/MultiplexedConnections.cpp +++ b/src/Client/MultiplexedConnections.cpp @@ -232,7 +232,7 @@ void MultiplexedConnections::sendIgnoredPartUUIDs(const std::vector & uuid void MultiplexedConnections::sendClusterFunctionReadTaskResponse(const ClusterFunctionReadTaskResponse & response) { std::lock_guard lock(cancel_mutex); - if (cancelled) + if (cancelled || !current_connection || !current_connection->isConnected()) return; current_connection->sendClusterFunctionReadTaskResponse(response); } @@ -241,7 +241,7 @@ void MultiplexedConnections::sendClusterFunctionReadTaskResponse(const ClusterFu void MultiplexedConnections::sendMergeTreeReadTaskResponse(const ParallelReadResponse & response) { std::lock_guard lock(cancel_mutex); - if (cancelled) + if (cancelled || !current_connection || !current_connection->isConnected()) return; current_connection->sendMergeTreeReadTaskResponse(response); } @@ -527,9 +527,12 @@ MultiplexedConnections::ReplicaState & MultiplexedConnections::getReplicaForRead void MultiplexedConnections::invalidateReplica(ReplicaState & state) { + Connection * old_connection = state.connection; state.connection = nullptr; state.pool_entry = IConnectionPool::Entry(); --active_connection_count; + if (current_connection == old_connection) + current_connection = nullptr; } void MultiplexedConnections::setAsyncCallback(AsyncCallback async_callback)