Skip to content

Commit 2cb868b

Browse files
Backport #95466 to 26.1: Avoid possible crash for distributed queries in case of cancellation
1 parent 258cf0a commit 2cb868b

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
@@ -84,6 +84,7 @@ namespace ErrorCodes
8484
extern const int SUPPORT_IS_DISABLED;
8585
extern const int BAD_ARGUMENTS;
8686
extern const int EMPTY_DATA_PASSED;
87+
extern const int LOGICAL_ERROR;
8788
}
8889

8990
Connection::~Connection()
@@ -1326,6 +1327,11 @@ Packet Connection::receivePacket()
13261327
{
13271328
try
13281329
{
1330+
/// We are trying to send something to already disconnected connection,
1331+
/// this means that we continue using Connection after exception.
1332+
if (!in)
1333+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Connection to {} is terminated", getDescription());
1334+
13291335
Packet res;
13301336

13311337
/// 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)