Skip to content

Do not share line editor state between concurrent embedded client sessions - #125510

Merged
alexey-milovidov merged 16 commits into
masterfrom
fix-embedded-replxx-shared-state
Oct 26, 2026
Merged

alexey-milovidov merged 16 commits into
masterfrom
fix-embedded-replxx-shared-state

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Client sessions embedded into the server (/webterminal and SSH) run concurrently in one process, so the line editor must not keep per-session state in process-wide variables.

Most of the original fix of this PR has landed in master through other pull requests in the meantime:

What remains in this PR:

  • replxx_last_is_delimiter (which decides whether Enter commits the query in multiline mode) is replaced by the last_is_delimiter member of ReplxxLineReader, reported by the highlighter callback. The state belongs to the session, not to whichever thread happens to run it, and ReplxxLineReader::setLastIsDelimiter is removed.
  • A stateless test 05445_webterminal_concurrent_sessions_input that opens two /webterminal sessions and sends their queries byte by byte, interleaved, with multi-byte UTF-8 characters split across frames, and checks that each session decodes its own query. It passes on master too (the fixes are already there), and serves as a regression test.

Related: #126120
Related: #125514
Related: ClickHouse/replxx#44
Related: ClickHouse/replxx#49

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Keep the "last token is a delimiter" state of the line editor per session instead of per thread.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.798-master (included in 26.11 and later)
  • Backported to: 26.10.3.14, 26.9.26.24, 26.8.35.21, 26.3.61.15

…sions

Client sessions embedded into the server (the web terminal and SSH) run
concurrently in one process, but the line editor kept some of its state in
process-wide variables:

- `replxx_last_is_delimiter` in `ReplxxLineReader.cpp`, which decides whether
  Enter commits the query in multiline mode. It is now a member of
  `ReplxxLineReader`, reported by the highlighter callback.
- In replxx: the receiver of `SIGWINCH`, the partially read UTF-8 sequence in
  `read_unicode_character` (concurrent multi-byte input could corrupt each
  other, and a race allowed a one-byte out-of-bounds write), the modifiers of
  the escape sequence being parsed, and the buffer of `ansi_color`.

An embedded client no longer installs the `SIGWINCH` handler in the server
process: its terminal size is updated by the server, and replxx queries it on
every refresh.

Related: ClickHouse/clickhouse-private#80922

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

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd7aad2]

Summary: ✅


AI Review

Summary

PR #125510 moves delimiter tracking from thread-local storage into each ReplxxLineReader and adds a stateless test for concurrent /webterminal input. No unresolved findings remain in the current diff; the structural refactor does not require the previously requested probabilistic race test.

Missing context / blind spots
  • ⚠️ Full build and stateless jobs for head cd7aad27ee8216bdc918e11b0e862954ad75b697 are still pending; no local build or live server was available. Fast test passed, and the added stateless test passed three times on the preceding head in the CI report. Completed latest-head results would close this validation gap.
Final Verdict

Status: ✅ Approve. No new inline findings.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default submodule changed At least one submodule changed in this PR. labels Oct 12, 2026
@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 12, 2026
Comment thread src/Client/ReplxxLineReader.cpp Resolved
`master` of `replxx` now contains the fix of the shared terminal state. The new
commit merges it with the history recall changes used by ClickHouse and fixes
Ctrl-V blocking after the esc delay support from `master`.

Related: ClickHouse/replxx#44
Related: ClickHouse/replxx#46

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Client/ReplxxLineReader.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cd7aad27e with master c7b68329f (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

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

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +4.3 s (+6%) in total before that adjustment.

Job report

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The previous `replxx` commit had a regression from the esc delay support in
`replxx` `master`: Meta with escape sequences (e.g. Meta+Up) was not recognized,
and `04909_client_hints_history_navigation` (`meta_up_recall_no_hints`) failed in
every stateless test job:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125510&sha=33773832dc78e5a5e773171f8b489ca21d9bd77a&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
#125510

The new commit is current `replxx` `master` (which also has the UTF-8 decoder
state kept per `Terminal` from ClickHouse/replxx#47)
plus the fix.

Related: ClickHouse/replxx#48

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread contrib/replxx Resolved
alexey-milovidov and others added 2 commits October 13, 2026 21:25
The same tree as the previous `replxx` commit, now merged into `replxx` `master`
via ClickHouse/replxx#48.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 3 commits October 13, 2026 21:57
…dth on refresh

Address review: `read_unicode_character` decoded an uninitialized byte when `poll`
reported only `POLLHUP`/`POLLERR`/`POLLNVAL`, and the embedded client, which does
not install the `SIGWINCH` handler, kept rendering against the startup width after
a resize. Both are fixed in ClickHouse/replxx#49.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts:
- `contrib/replxx`: kept the pointer of this PR (`33a566d`). It already
  contains the `Ctrl-Z` fix in incremental history search that `master`
  points to (`00cd994`, merged into `replxx` `master` as `91703bf`), together
  with the Meta+Up fix, the thread-local decoder state, and the hangup and
  terminal width fixes this PR needs.
- `src/Client/ReplxxLineReader.cpp`: kept the comment of this PR about
  `SIGWINCH`, which matches re-reading the terminal width on every refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll2 added a commit that referenced this pull request Oct 27, 2026
Cherry pick #125510 to 26.3: Do not share line editor state between concurrent embedded client sessions
robot-clickhouse added a commit that referenced this pull request Oct 27, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 27, 2026
Cherry pick #125510 to 26.8: Do not share line editor state between concurrent embedded client sessions
robot-clickhouse added a commit that referenced this pull request Oct 27, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 27, 2026
Cherry pick #125510 to 26.9: Do not share line editor state between concurrent embedded client sessions
robot-clickhouse added a commit that referenced this pull request Oct 27, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 27, 2026
Cherry pick #125510 to 26.10: Do not share line editor state between concurrent embedded client sessions
robot-clickhouse added a commit that referenced this pull request Oct 27, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 27, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 27, 2026
Backport #125510 to 26.10: Do not share line editor state between concurrent embedded client sessions
clickhouse-gh Bot added a commit that referenced this pull request Oct 27, 2026
Backport #125510 to 26.9: Do not share line editor state between concurrent embedded client sessions
clickhouse-gh Bot added a commit that referenced this pull request Oct 27, 2026
Backport #125510 to 26.8: Do not share line editor state between concurrent embedded client sessions
alexey-milovidov added a commit that referenced this pull request Oct 27, 2026
Backport #125510 to 26.3: Do not share line editor state between concurrent embedded client sessions
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
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
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
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-cli clickhouse-client (interactive CLI) and client library. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants