Repository navigation
fix(db): a ClickHouse user in readonly mode connects - #58
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)".max_execution_time. Over HTTP that includes the server-hello query of every new connection. ClickHouse contexts now reach the driver without their deadline, and are still cancelled when it passes. DBeaver sends no limit either. Upstream removed this rule onmain(fix: do not derive max_execution_time from the context deadline ClickHouse/clickhouse-go#2101, issue Client sets max_execution_time, which is incompatible with read-only mode ClickHouse/clickhouse-go#1748), but no release has it yet. RemovedriverContextonce one does.readonly=2. Areadonly=1user rejects that, and areadonly=2user rejectsreadonly=1. The app now reads the user's ownreadonlyfirst, with one query as the connection opens, and sendsreadonly=2only to a user that may write.Trade-off: over HTTP, a query whose deadline passes can keep running on the server until it finishes, unless the server sets
max_execution_timeorcancel_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 checkpassesgo run ./tools/dev test --itpasses, if the change touchesinternal/db: only the ClickHouse integration tests were run (37 pass, includingTestIntegrationReadOnly/ch). The other engines' servers were not running.New test:
TestIntegrationClickHouseReadonlyUsercovers areadonly=1user over native and HTTP, with Read-only on and off. Without the fix it fails with the error above. I also checked by hand:readonly=2user with Read-only on: writes are refused, and reads with aSETTINGSclause work.SELECT sleep(3)after 1 second, withcontext deadline exceeded, over both protocols.Engines tested against: ClickHouse 26.10
Screenshots
None: no UI change.