ClickHouse: Allow cancelling queries in the middle of blocking operations

Queries can be canceled only at specific points between blocks processing. However, a query may get stuck on a blocking operation like reading/writing from/to a socket. In this case, it has to wait for receive_timeout/send_timeout (default is 300 seconds, can be changed to a higher value) and cannot be killed/canceled.

However, we know ids of all threads executing a query. So we can send a signal to these threads and make them exit from a blocking syscall with EINTR. After that, we can check a flag in ThreadStatus/ThreadGroup before resuming the syscall and throw an exception if the query was canceled.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 7
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@serxa, throwing inside the EINTR loop + cancellable mutex could suffice.

It can be more natural to cap receive_timeout/send_timeout by the remaining max execution time before all socket operations.

It makes sense, but it will not help when execution time is not limited. This issue is about KILL QUERY and Ctrl-C, not about max execution time.

We can start by simply adding a check for a cancellation flag because we already have the (real-time) query profiler that sends a signal each 1 second by default.