Skip to content

Commit

Permalink
Merge pull request #65206 from azat/fix-hedged-requests
Browse files Browse the repository at this point in the history
Fix possible crash for hedged requests
  • Loading branch information
Avogar authored Jun 18, 2024
2 parents 48a6f22 + ff6d1d0 commit e608514
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Client/HedgedConnections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ void HedgedConnections::sendCancel()
if (!sent_query || cancelled)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot cancel. Either no query sent or already cancelled.");

/// All hedged connections should be stopped, since otherwise before the
/// HedgedConnectionsFactory will be destroyed (that will happen from
/// QueryPipeline dtor) they could still do some work.
/// And not only this does not make sense, but it also could lead to
/// use-after-free of the current_thread, since the thread from which they
/// had been created differs from the thread where the dtor of
/// QueryPipeline will be called and the initial thread could be already
/// destroyed (especially when the system is under pressure).
if (hedged_connections_factory.hasEventsInProcess())
hedged_connections_factory.stopChoosingReplicas();

cancelled = true;

for (auto & offset_status : offset_states)
Expand Down

0 comments on commit e608514

Please sign in to comment.