Skip to content

Commit 73e4e10

Browse files
Backport #95466 to 25.10: Avoid possible crash for distributed queries in case of cancellation
1 parent 0734b00 commit 73e4e10

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/Client/Connection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace ErrorCodes
8585
extern const int SUPPORT_IS_DISABLED;
8686
extern const int BAD_ARGUMENTS;
8787
extern const int EMPTY_DATA_PASSED;
88+
extern const int LOGICAL_ERROR;
8889
}
8990

9091
Connection::~Connection()
@@ -1302,6 +1303,11 @@ Packet Connection::receivePacket()
13021303
{
13031304
try
13041305
{
1306+
/// We are trying to send something to already disconnected connection,
1307+
/// this means that we continue using Connection after exception.
1308+
if (!in)
1309+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Connection to {} is terminated", getDescription());
1310+
13051311
Packet res;
13061312

13071313
/// Have we already read packet type?

src/Processors/Sources/RemoteSource.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ void RemoteSource::onCancel() noexcept
249249

250250
void RemoteSource::onUpdatePorts()
251251
{
252+
if (isCancelled())
253+
return;
252254
if (getPort().isFinished())
253255
query_executor->finish();
254256
}

src/QueryPipeline/RemoteQueryExecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ void RemoteQueryExecutor::finish()
785785
* - received an unknown packet from one replica;
786786
* then you do not need to read anything.
787787
*/
788-
if (!isQueryPending() || hasThrownException())
788+
if (!isQueryPending() || hasThrownException() || was_cancelled)
789789
return;
790790

791791
/// To make sure finish is only called once

0 commit comments

Comments
 (0)