Skip to content

fix(db): a ClickHouse user in readonly mode connects - #58

Merged
saanuregh merged 1 commit into
mainfrom
fix/clickhouse-readonly-user
Nov 26, 2026
Merged

saanuregh merged 1 commit into
mainfrom
fix/clickhouse-readonly-user

Conversation

@saanuregh

Copy link
Copy Markdown
Owner

What and why

A ClickHouse user the server keeps in readonly mode (readonly=1) could not connect, not even with Test Connection. The server rejected settings the app changed: "Cannot modify 'max_execution_time' setting in readonly mode (READONLY)".

Trade-off: over HTTP, a query whose deadline passes can keep running on the server until it finishes, unless the server sets max_execution_time or cancel_http_readonly_queries_on_client_close. Over the native protocol, the driver still sends a cancel.

How it was tested

Linux, against a local ClickHouse 26.10 server.

  • go run ./tools/dev check passes
  • go run ./tools/dev test --it passes, if the change touches internal/db: only the ClickHouse integration tests were run (37 pass, including TestIntegrationReadOnly/ch). The other engines' servers were not running.

New test: TestIntegrationClickHouseReadonlyUser covers a readonly=1 user over native and HTTP, with Read-only on and off. Without the fix it fails with the error above. I also checked by hand:

  • A readonly=2 user with Read-only on: writes are refused, and reads with a SETTINGS clause work.
  • A 1-second timeout still stops SELECT sleep(3) after 1 second, with context deadline exceeded, over both protocols.

Engines tested against: ClickHouse 26.10

Screenshots

None: no UI change.

A user the server keeps in readonly mode (readonly=1) may not change
any setting, and the app changed two, so it could not even test the
connection: "Cannot modify 'max_execution_time' setting in readonly
mode".

- clickhouse-go v2.51.0 sends a context's deadline as
  max_execution_time, over HTTP on the server-hello query of every new
  connection. The driver now gets ClickHouse contexts without their
  deadline, still cancelled when it passes; DBeaver sends no limit
  either. Upstream removed the rule on main (ClickHouse/clickhouse-go
  #2101, issue #1748), not yet released: drop driverContext then.
- A connection marked Read-only sent readonly=2, which a readonly=1 user
  refuses, while a readonly=2 user refuses 1. It now reads the user's
  readonly first and sends 2 only to a user that may write.

TestIntegrationClickHouseReadonlyUser covers both protocols with
Read-only on and off; it failed before.
@saanuregh
saanuregh merged commit 9932271 into main Nov 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant