Skip to content

Commit

Permalink
Merge pull request #52862 from Avogar/local-assert
Browse files Browse the repository at this point in the history
Fix possible assert in ~PushingAsyncPipelineExecutor in clickhouse-local
  • Loading branch information
Avogar committed Aug 4, 2023
2 parents 376eeeb + cd33bd1 commit d4441fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Client/LocalConnection.cpp
Expand Up @@ -35,6 +35,18 @@ LocalConnection::LocalConnection(ContextPtr context_, bool send_progress_, bool

LocalConnection::~LocalConnection()
{
/// Last query may not have been finished or cancelled due to exception on client side.
if (state && !state->is_finished && !state->is_cancelled)
{
try
{
LocalConnection::sendCancel();
}
catch (...)
{
/// Just ignore any exception.
}
}
state.reset();
}

Expand Down Expand Up @@ -73,6 +85,10 @@ void LocalConnection::sendQuery(
bool,
std::function<void(const Progress &)> process_progress_callback)
{
/// Last query may not have been finished or cancelled due to exception on client side.
if (state && !state->is_finished && !state->is_cancelled)
sendCancel();

/// Suggestion comes without client_info.
if (client_info)
query_context = session.makeQueryContext(*client_info);
Expand Down Expand Up @@ -204,6 +220,10 @@ void LocalConnection::sendCancel()
state->is_cancelled = true;
if (state->executor)
state->executor->cancel();
if (state->pushing_executor)
state->pushing_executor->cancel();
if (state->pushing_async_executor)
state->pushing_async_executor->cancel();
}

bool LocalConnection::pullBlock(Block & block)
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02841_local_assert.reference
@@ -0,0 +1 @@
1
18 changes: 18 additions & 0 deletions tests/queries/0_stateless/02841_local_assert.sh
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh

echo "create table test (x UInt64) engine=Memory;
insert into test from infile 'data'; -- {clientError BAD_ARGUMENTS}" | $CLICKHOUSE_LOCAL -nm

echo "create table test (x UInt64) engine=Memory;
insert into test from infile 'data';" | $CLICKHOUSE_LOCAL -nm --ignore-error

echo "create table test (x UInt64) engine=Memory;
insert into test from infile 'data'; -- {clientError BAD_ARGUMENTS}
select 1" | $CLICKHOUSE_LOCAL -nm

0 comments on commit d4441fe

Please sign in to comment.