diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 19244134617e..fc1163469465 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -1147,7 +1147,18 @@ void ClientBase::onEndOfStream() bool is_running = false; output_format->setStartTime( clock_gettime_ns(CLOCK_MONOTONIC) - static_cast(progress_indication.elapsedSeconds() * 1000000000), is_running); - output_format->finalize(); + + try + { + output_format->finalize(); + } + catch (...) + { + /// Format should be reset to make it work for subsequent query + /// (otherwise it will throw again in resetOutput()) + output_format.reset(); + throw; + } } resetOutput(); diff --git a/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.reference b/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.reference new file mode 100644 index 000000000000..7b36cc96f5ec --- /dev/null +++ b/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.reference @@ -0,0 +1,20 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.sh b/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.sh new file mode 100755 index 000000000000..cc4ce9b122e3 --- /dev/null +++ b/tests/queries/0_stateless/02871_clickhouse_client_restart_pager.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +# head by default print 10 rows, but it is not enough to query 11 rows, since +# we need to overflow the default pipe size, hence just 1 million of rows (it +# should be around 6 MiB in text representation, should be definitelly enough). +$CLICKHOUSE_CLIENT --ignore-error -nm --pager head -q " + select * from numbers(1e6); -- { clientError CANNOT_WRITE_TO_FILE_DESCRIPTOR } + select * from numbers(1e6); -- { clientError CANNOT_WRITE_TO_FILE_DESCRIPTOR } +" + +exit 0