Skip to content

Apply the session limits of other interfaces to the web terminal - #125514

Merged
alexey-milovidov merged 11 commits into
masterfrom
webterminal-session-limits
Oct 22, 2026
Merged

alexey-milovidov merged 11 commits into
masterfrom
webterminal-session-limits

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

A /webterminal session holds a server thread, a thread for the embedded clickhouse-client, and a pseudoterminal. Before this change it never expired, and max_sessions_for_user was only checked asynchronously in the embedded client thread, after the pseudoterminal and the thread had been allocated.

This change applies the same limits that other interfaces use, taken from the settings of the authenticated user:

  • The session context is created in WebTerminalRequestHandler right after authentication, before the pseudoterminal and the client thread are allocated. A session over max_sessions_for_user is rejected with the WebSocket close code 1008.
  • The session is closed after idle_connection_timeout seconds without traffic in either direction while the embedded client waits at the prompt, as TCPHandler does for native protocol connections waiting for the next query. A running query is never interrupted by this timeout.
  • The socket timeouts use receive_timeout and send_timeout instead of the hardcoded 30 seconds.

The documentation of the web terminal gets a new section about these limits.

Changelog category (leave one):

  • Improvement

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

The web terminal (/webterminal) now applies the same limits as other interfaces: max_sessions_for_user is checked before a session is started, an idle session is closed after idle_connection_timeout, and receive_timeout and send_timeout are applied to the WebSocket connection.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125514]

Version info

  • Merged into: 26.11.1.566-master (included in 26.11 and later)

A web terminal session holds a server thread, a thread for the embedded
client, and a pseudoterminal, but previously it never expired and
`max_sessions_for_user` was checked only asynchronously in the client thread.

Now the session context is created in `WebTerminalRequestHandler` before
the pseudoterminal and the client thread are allocated, so a session over
`max_sessions_for_user` is rejected with the close code `1008`. The session
is closed after `idle_connection_timeout` seconds without traffic, as in
`TCPHandler`, and the socket timeouts use the user's `receive_timeout` and
`send_timeout` instead of hardcoded values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 22, 2026, 8:50 AM

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aa63247]

Summary: ✅


AI Review

Summary

The PR applies authenticated users' session and socket limits to /webterminal, checks max_sessions_for_user before allocating the embedded client, and refreshes timeouts after queries. It also isolates progress and line-reader state between concurrent clients. The four previous inline findings are addressed in the current code. No new actionable findings remain.

Missing context / blind spots
  • ⚠️ Current-head functional and sanitizer results are still pending in CI for aa632476. No local build or server was available. The focused 05385_webterminal_session_limits test passed all 50 runs in the previous binary flaky check; completion of current-head CI would close this validation gap.
Final Verdict

Status: ✅ Approve. No code changes requested; current-head CI remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 12, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Oct 12, 2026
…uery in the web terminal

`TCPHandler` applies `idle_connection_timeout` only while waiting for the next
query, so a long silent query over the native protocol is not interrupted.
The web terminal now does the same: the idle timer runs only while the embedded
client waits at the prompt. `ClientBase::runInteractive` sets a flag provided by
`ClientEmbeddedRunner` around reading the query.

The test checks that a query longer than `idle_connection_timeout` completes and
that the session is closed after it becomes idle again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125514&sha=78d1e9965059e88fefe5575e0677428c6d85acff&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%201%2F4%29 (test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads, Spark fails to refresh the Iceberg table from S3) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The TSan data race on replxx::_terminal_ in Stateless tests (amd_tsan, flaky check) happens when several embedded clients run concurrently (the parallel runs of the new web terminal test). It is not caused by this PR and is addressed by #125510.

@groeneai

Copy link
Copy Markdown
Collaborator

The test_concurrent_reads failure is fixed by #125448 (merged 2026-10-13 01:47Z), which this run did not include: the job tested 78d1e996 merged into d47196fa (master at 2026-10-12 21:09Z), 88 commits behind the fix.

The error (UnknownStoreException on s3a://root/..., NoSuchBucket) is the mechanism #125448 fixes: the test ran on xdist worker gw2 right after test_storage_delta/test_writes_interop.py, in the same reused Spark JVM, which still held a cached S3A filesystem from that module. The isolated retry on a fresh worker passed.

On master since the merge: 117 OK, 1 FAIL, and that failure (3ab409c7e8) is on a commit before the fix. The new head 891ecb8 is tested on a master that already contains it, so no new PR is needed.

alexey-milovidov and others added 2 commits October 14, 2026 13:22
…of timeouts in the web terminal

A zero `receive_timeout` now disables the per-frame deadline instead of
making every frame read time out immediately, as for other interfaces.

`receive_timeout`, `send_timeout` and `idle_connection_timeout` are re-read
from the session context whenever the embedded client returns to the prompt,
as `TCPHandler` re-reads them after each query, so a `SET` typed in the
terminal takes effect. The embedded client reports prompt entries through a
callback, and the runner counts them, so that a short query finishing between
two iterations of the handler loop is not missed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125514&sha=891ecb8c33a683661d76af3fe7381895c2577db3&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 (05230_materialized_cte_shared_by_two_ctes_in_set_subquery with parallel replicas: Unknown table expression identifier _materialized_cte_d_... on a replica; the test was added on master in #121010 and is unrelated to the web terminal) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The TSan data race on replxx::_terminal_ in Stateless tests (amd_tsan, flaky check) is still the known one addressed by #125510 (open).

@groeneai

Copy link
Copy Markdown
Collaborator

This is #112642, fixed by #123121 (merged 2026-10-13 22:15Z; its description names this test). The failing job built 5b989354f (891ecb8c merged into master 50b17deb63d), which does not contain the fix: it is 313 commits behind the #123121 merge commit 74ed0312f31, and the fix's test 05296_parallel_replicas_materialized_cte_in_set_subquery is absent there. Your fb34b5d8432 includes the fix, so the next run of this PR picks it up. Since the merge, all 30 ParallelReplicas runs of this test on master passed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125514&sha=fb34b5d8432f91ec51c731e4efa9f64aabcc96fd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 (Logical error: Reading from materialized CTE 'c' before its materialization completed - DelayedPortsProcessor gate is missing in the query plan, STID 2467-34d3, a chain of MATERIALIZED CTEs inside a PREWHERE ... IN subquery over remoteSecure; this PR only touches the web terminal) and provide a fix in a separate PR. If the fix is already in progress (e.g. #121688), link it here.

The other failures of this run are not related either:

@groeneai

Copy link
Copy Markdown
Collaborator

This is the bug my open #121688 fixes. The shard-local re-analysis of the remote read sees c and d by name only and puts both writers at the same level, so d's writer reads c before c is complete. The explicit PREWHERE builds the set in place (ReadFromMergeTree::applyFilters), which is why v does not need to be in the key.

Measured with this query (remoteSecure('127.0.0.1:9440') replaced by remote('127.0.0.1:<tcp_port>'), the fuzzed t_05230__fuzz_0 DDL from the job log, four one-row parts, max_threads = 3):

So no separate PR is needed. #121688 is waiting for a re-review after the requested topological-sort change.

@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing aa632476b with master 915c5e7f3 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

23 translation units recompiled, 134 s compile time in total, 23 of them have a recent master baseline.

Job report

`ProgressIndication::writeProgress` kept the frame of the spinning indicator
in a function-local `static`, which is shared by all clients in the process.
Concurrent sessions of the web terminal (embedded clients) increment it from
several threads, which TSan reports as a data race.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125514&sha=c65e37be6033d108fd90297dd81f761c23a15cad&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20targeted%29
#125514

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai, #121688 tracks the remoteSecure materialized CTE error.

The latest TSan run (c65e37be) found a second race in the concurrent web terminal sessions: ProgressIndication::writeProgress kept its spinner frame in a function-local static that every embedded client in the process shared. Commit 3329e92 moves it into a per-instance member. The replxx::_terminal_ race is still covered by #125510 (open). The 02149_read_in_order_fixed_prefix failure is covered by #125715.

alexey-milovidov and others added 2 commits October 18, 2026 04:16
The embedded client repaints the progress indicator on every progress and profile
events packet, sent every `interactive_delay` (100 ms by default), so the terminal
output alone kept the session alive and the case passed even without the
`isWaitingForQueryInput` guard. A query-local `interactive_delay` longer than the
query makes it silent. Verified locally: the case fails without the guard and
passes with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (f9f1dce8). The two failures on 265b67e3:

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is my open #125562. It passes --skip 05082_kill_and_system_on_cluster_access_types to the stress phase of the upgrade check.

This run shows the same chain as the other carriers. The previous release (26.9.21.9) retried the KILL PART_MOVE_TO_SHARD ... ASYNC entry from 05082 (query-0000000015) 200 times between 10:12 and 10:29, each time with Code: 999 ... Session expired, and never started a later entry. The 02907 BACKUP ... ON CLUSTER entry (query-0000000020) was queued behind it. The pre-upgrade KILL QUERY WHERE 1 SYNC cancelled its initiator at 10:26. The upgraded server then replayed query-0000000020 and got Got error from the initiator ... Query was cancelled.

#125562 passes its own CI but nobody has reviewed it yet. Until it is merged, this check will keep failing on unrelated PRs.

JTCunning pushed a commit to JTCunning/ClickHouse that referenced this pull request Oct 21, 2026
…s all-constant

The parallel final DISTINCT (ClickHouse#114550) hands its ScatterByPartitionTransform
lanes downstream as separate streams, and a scatter holds its input chunk
until every unfinished lane has accepted its piece, so the lanes are coupled.
A full sort normally decouples them, because MergeSortingTransform consumes
its whole input first. When every sort key is a constant, SortingTransform
strips them all and MergeSortingTransform::consume passes chunks through,
yet SortingStep::fullSort still merged the lanes with MergingSortedTransform.
With all keys equal the cursor tie-break is the source number, so the merge
asks for its first input only, until that input finishes. The first lane
finishes only after every scatter has finished, and a scatter cannot finish
while the lanes the merge does not read are full: Pipeline stuck (a logical
error, so debug and sanitizer servers abort).

Reachable without the fuzzer, e.g.
  SELECT * FROM (SELECT DISTINCT 'x' AS c, number FROM numbers_mt(100000))
  ORDER BY c SETTINGS max_threads = 4, max_block_size = 100
and with a window OVER (ORDER BY <constant>). DISTINCT and ORDER BY in the
same SELECT are not affected: preserveInputOrder() forbids the scatter there.

An all-constant description orders nothing, so any interleaving is a valid
result. fullSort now combines such streams with resize(1), whose
ResizeProcessor drains whichever input is ready. This is the remedy that
5e1ec58 (ClickHouse#114626) applied to GatherSendStep for the same wedge; its
helper sortDescriptionIsAllConstant moves to Core/SortDescription so both
sites share it (no behaviour change in GatherSendStep). The stage grouping
used by EXPLAIN PIPELINE is kept, virtual rows are still removed in the
shared non-merge branch, and the top-K threshold tracker is skipped because
it belongs to the merge. A limit on the sorting step is only a hint pushed
down from the LimitStep that stays above it, and the single-stream path
already relied on that, so LIMIT and WITH TIES stay correct.

Found by AST fuzzer (amd_debug, targeted) on
ClickHouse#125514

The new test fails with Pipeline stuck before this change and passes after
it, also 50/50 with randomized settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits October 22, 2026 08:19
Concurrent web terminal sessions run several embedded clients in the same
server process. The flag set by the highlighter and read by the Enter key
handler was a process-wide `static`, so one session's highlighter raced with
another session's Enter handler (TSan data race at
`src/Client/ReplxxLineReader.cpp:620`). Both callbacks run on the thread of
the session's input loop, so a thread-local flag keeps each session separate.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125514&sha=f9f1dce80eb9002556db97367c45bd87daf42a8c&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
#125514

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 2f9905bd and merged master (aa632476). The failures on f9f1dce8:

  • Stateless tests (amd_tsan, flaky check), ThreadSanitizer: data race at src/Client/ReplxxLineReader.cpp:620 (STID 3626-35f0, report). This was a third piece of process-wide state shared by concurrent embedded clients: replxx_last_is_delimiter, which the highlighter writes and the Enter key handler reads, was a plain static. 2f9905bd makes it thread_local. Both callbacks run on the thread of the session's input loop. The Server liveness check failed in the same job comes from the server stopping on that TSan report. The replxx::_terminal_ race is still covered by Do not share line editor state between concurrent embedded client sessions #125510 (open).
  • AST fuzzer (amd_debug, targeted), Logical error: Pipeline stuck (STID 4940-37c0) on ORDER BY ALL over all-constant toTypeName columns after SELECT DISTINCT. This is fixed by Do not merge-sort the streams of an all-constant full sort fed by a fan-out #126992, which was merged on 2026-10-20 after f9f1dce8 was built. The master merge brings in that fix.

@groeneai, thanks. #125562 tracks the Upgrade check failure.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit e1eda99 Oct 22, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the webterminal-session-limits branch October 22, 2026 18:07
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 29, 2026
…ress-indicator-frame

Backport #125514 to 26.10: Make the progress indicator frame per-instance in `ProgressIndication`
clickhouse-gh Bot added a commit that referenced this pull request Oct 29, 2026
…ess-indicator-frame

Backport #125514 to 26.9: Make the progress indicator frame per-instance in `ProgressIndication`
PedroTadim added a commit that referenced this pull request Oct 29, 2026
…ess-indicator-frame

Backport #125514 to 26.8: Make the progress indicator frame per-instance in `ProgressIndication`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
`ProgressIndication::writeProgress` kept the frame of the spinning indicator
in a function-local `static`, which is shared by all clients in the process.
Concurrent sessions of the web terminal (embedded clients) increment it from
several threads, which TSan reports as a data race. It fails every
`Stress test (amd_tsan)` run since `05445_webterminal_concurrent_sessions_input`
came with the backport of #125510.

Backport of 3329e92 from #125514 (only this commit; the rest of the PR is
a feature).

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=26.10&sha=da23b6505a74b35f9ef57cb2a3a26665db3fd763&name_0=ReleaseBranchCI
#125514

(cherry picked from commit 3329e92)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
`ProgressIndication::writeProgress` kept the frame of the spinning indicator
in a function-local `static`, which is shared by all clients in the process.
Concurrent sessions of the web terminal (embedded clients) increment it from
several threads, which TSan reports as a data race. It fails every
`Stress test (amd_tsan)` run since `05445_webterminal_concurrent_sessions_input`
came with the backport of #125510.

Backport of 3329e92 from #125514 (only this commit; the rest of the PR is
a feature).

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=26.10&sha=da23b6505a74b35f9ef57cb2a3a26665db3fd763&name_0=ReleaseBranchCI
#125514

(cherry picked from commit 3329e92)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
`ProgressIndication::writeProgress` kept the frame of the spinning indicator
in a function-local `static`, which is shared by all clients in the process.
Concurrent sessions of the web terminal (embedded clients) increment it from
several threads, which TSan reports as a data race. It fails every
`Stress test (amd_tsan)` run since `05445_webterminal_concurrent_sessions_input`
came with the backport of #125510.

Backport of 3329e92 from #125514 (only this commit; the rest of the PR is
a feature).

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=26.10&sha=da23b6505a74b35f9ef57cb2a3a26665db3fd763&name_0=ReleaseBranchCI
#125514

(cherry picked from commit 3329e92)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — aa632476 Deployed Oct 22, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... 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.

3 participants