Skip to content

Cancel query on Ctrl-C when --pager used#88935

Merged
azat merged 10 commits intoClickHouse:masterfrom
GSokol:fix/fix-80778_ctrl-c_is_ignored
Oct 31, 2025
Merged

Cancel query on Ctrl-C when --pager used#88935
azat merged 10 commits intoClickHouse:masterfrom
GSokol:fix/fix-80778_ctrl-c_is_ignored

Conversation

@GSokol
Copy link
Copy Markdown
Contributor

@GSokol GSokol commented Oct 24, 2025

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

User can now cancel the query by pressing Ctrl-C when the pager is running. Resolves #80778

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Details

Trying to process SIGINT query and terminate the pager. I have great concerns about what should be done: different pagers behave differently. Some could pass-through the signal, some -- not. Different signals could be handled differently, etc. The patch is more like a fast-and-dirty fix of particular use cases:

pagers: more, less
queries:

  • SELECT 3
  • SELECT * FROM numbers(1e12) format Null
  • SELECT * FROM numbers(300)

behavior:

  • try to wait for result (for short queries) and exit from pager
  • for long-running queries, try cancel and then assert that pager is terminated

Resolves #80778

Trying to process SIGINT query and terminate the pager. I have a great
concerns about what should be done: different pages behaves differently.
Some could path-through the signal, some -- not. Different signals could
be handled differently, etc. The patch is more like fast-and-dirty fix
of particular use cases:

pagers: `more`, `less`
queries:
  - `SELECT 3`
  - `SELECT * FROM numbers(1e12) format Null`
  - `SELECT * FROM numbers(300)`

behavior:
  - try to wait for result (for short queries) and exit from pager
  - for long-running queries, try cancel and then assert that pager is
    terminated
@GSokol
Copy link
Copy Markdown
Contributor Author

GSokol commented Oct 24, 2025

@GSokol
Copy link
Copy Markdown
Contributor Author

GSokol commented Oct 24, 2025

@azat, could you take a look?

@azat azat self-assigned this Oct 25, 2025
Copy link
Copy Markdown
Member

@azat azat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!

Looks OK, but let's add a test, I do not want to break it again (you can take a look at expect tests, and use query like select sleepEachRow(1) from numbers(30) settings max_block_size=1, function_sleep_max_microseconds_per_block=30e6)

Can you also address minor issues here:

@GSokol
Copy link
Copy Markdown
Contributor Author

GSokol commented Oct 26, 2025

@azat, here is the test. BTW, I struggled to test proper less exit q, no clue, how to do it. Tried send -- "q" and echo 'q' >> /proc/${LESS_PID}/fd/0.

@azat
Copy link
Copy Markdown
Member

azat commented Oct 27, 2025

I struggled to test proper less exit q, no clue, how to do it. Tried send -- "q" and echo 'q' >> /proc/${LESS_PID}/fd/0.

Hm, I think it should simply by sending q to the cilent, but the problem is that you need to make sure that the pager already started by the client, anyway, it is not a requirement for this test

@azat
Copy link
Copy Markdown
Member

azat commented Oct 27, 2025

@GSokol what about two other issues?

@azat azat added the can be tested Allows running workflows for external contributors label Oct 27, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Oct 27, 2025

Workflow [PR], commit [8099349]

Summary:

job_name test_name status info comment
Stateless tests (amd_binary, old analyzer, s3 storage, DatabaseReplicated, parallel) failure
01201_read_single_thread_in_order FAIL cidb, flaky
Integration tests (amd_asan, old analyzer, 2/6) failure
test_storage_kafka/test_batch_slow_6.py::test_kafka_rebalance[generate_new_create_table_query-{}.*Saved offset] FAIL cidb
Integration tests (amd_asan, old analyzer, 3/6) failure
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[False-FLAT] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[True-FLAT] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[False-HASHED] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[True-HASHED] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[False-HASHED_ARRAY] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_id[True-HASHED_ARRAY] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_complex_key[True-COMPLEX_KEY_HASHED] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_complex_key[False-COMPLEX_KEY_HASHED] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_complex_key[True-COMPLEX_KEY_HASHED_ARRAY] FAIL cidb
test_ytsaurus/test_dictionaries.py::test_yt_dictionary_complex_key[False-COMPLEX_KEY_HASHED_ARRAY] FAIL cidb
8 more test cases not shown
Integration tests (amd_asan, old analyzer, 4/6) failure
test_scheduler_cpu_preemptive/test.py::test_downscaling[cpu-slot-preemption-timeout-1ms] FAIL cidb, flaky
test_backup_restore_on_cluster/test_slow_rmt.py::test_replicated_database_async FAIL cidb
OOM in dmesg FAIL cidb
Integration tests (arm_binary, distributed plan, 3/4) failure
test_backup_restore_on_cluster/test.py::test_async_backups_to_same_destination[http-False] FAIL cidb, flaky

@GSokol
Copy link
Copy Markdown
Contributor Author

GSokol commented Oct 27, 2025

@GSokol what about two other issues?

So:

  • missing redraw in case of cancellation, though I cannot reproduce it, but after a simple query (select sleepEachRow(1) from numbers(3) settings max_block_size=1) there was not prompt

As I understand this expectation insures, that the prompt is alweys remndered, isn't it?

and sometimes there are extra new lines - https://pastila.nl/?07b9abe6/d5d459bed20554da7ced8d4559429226#mU1u2N+22zv57/tl9tLobw==

I would check that there is no new line in the end.

@azat
Copy link
Copy Markdown
Member

azat commented Oct 27, 2025

As I understand this expectation insures, that the prompt is alweys remndered, isn't it?

Not exactly, when you launch client it does not execute pager yet, while the problem I found was that after pager had been executed and I pressed Ctrl-C, there was no prompt. Maybe you can try to reproduce it.

@azat
Copy link
Copy Markdown
Member

azat commented Oct 27, 2025

Also about changelog category, we are using Bug fix category only for major bugs, let's use Improvement for this one (and don't forget to set changelog entry, otherwise CI will not start)

@clickhouse-gh clickhouse-gh bot added the pr-improvement Pull request with some product improvements label Oct 27, 2025
@GSokol
Copy link
Copy Markdown
Contributor Author

GSokol commented Oct 27, 2025

Not exactly, when you launch client it does not execute pager yet, while the problem I found was that after pager had been executed and I pressed Ctrl-C, there was no prompt. Maybe you can try to reproduce it.

Sorry, the wrong line number. Here is the proper one.

@azat azat changed the title Cancel query on Ctr-C when --pager used Cancel query on Ctrl-C when --pager used Oct 29, 2025
@azat
Copy link
Copy Markdown
Member

azat commented Oct 29, 2025

try to wait for result (for short queries) and exit from pager

@GSokol can you point me to a relevant code in the patch for this behavior?

@clickhouse-gh clickhouse-gh bot added the manual approve Manual approve required to run CI label Oct 29, 2025
@azat azat enabled auto-merge October 30, 2025 12:51
@azat azat added this pull request to the merge queue Oct 31, 2025
@azat
Copy link
Copy Markdown
Member

azat commented Oct 31, 2025

@GSokol I've fixed the test and now it is ready to land! Thanks for taking a look into this.

Merged via the queue into ClickHouse:master with commit 365fc6d Oct 31, 2025
118 of 124 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctlr-C does not in case of --pager is used in client

3 participants