Skip to content

fix: do not set compression settings over HTTP for read-only users - #2121

Open
xmasdev wants to merge 3 commits into
ClickHouse:mainfrom
xmasdev:fix-http-compression-readonly
Open

xmasdev wants to merge 3 commits into
ClickHouse:mainfrom
xmasdev:fix-http-compression-readonly

Conversation

@xmasdev

@xmasdev xmasdev commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2118.

Since #1840 (v2.49.0) every HTTP request with CompressionLZ4 or CompressionZSTD sets network_compression_method, and network_zstd_compression_level for ZSTD with a level. The server rejects a request that changes a setting for a user with readonly = 1. The first request is the server hello query, so such a user cannot open a connection when the configured codec or level is not the server default. On 26.9 that includes CompressionLZ4 and compress=true in a DSN.

What changes:

  • The server hello query does not send the two settings, and it also reads getSetting('readonly').
  • Later requests send the two settings only when readonly is not 1. With readonly = 2 the user can change settings, so nothing changes there.
  • compress=1 and decompress=1 are HTTP parameters and not settings, so they are still sent for every user. A read-only user gets responses in the server's codec. The reader takes the codec from each compressed frame, so decoding does not depend on the setting.
  • The two settings are not replaced when the caller already set them in Options.Settings or for the query. Before, a connection-level network_compression_method was replaced by the per-request value, and the ZSTD level was replaced in both cases.

For users that can change settings the configured codec and level still apply, so Test1772_HTTPNativeCompressionMethodSettings passes unchanged.

I read readonly as toUInt8(getSetting('readonly')) because the type of the bare getSetting result is not something I wanted the scan to depend on.

This does not touch max_execution_time (#1748, #1107). A read-only user still needs a DialTimeout of 1s or less over HTTP, and the new test sets that.

Checklist

  • Unit and integration tests covering the common scenarios were added

Test2118 creates a readonly = 1 user and queries over HTTP with LZ4, ZSTD, and ZSTD with levels 1 and 9, through clickhouse.Open and database/sql. Test2118_ConnectionSettings checks that values from Options.Settings are kept and that a per-query value still has priority. I ran them on 26.9 (default ZSTD) and 26.3 (default LZ4). On main the LZ4 and ZSTD level cases fail on 26.9 with READONLY.


Note

Medium Risk
Touches HTTP native compression on every query/batch path; behavior changes for read-only users and when compression settings are pre-configured, though scope is narrow and well-tested.

Overview
Fixes HTTP connections failing for users with readonly = 1 when LZ4/ZSTD compression is enabled, because the client was sending network_compression_method and network_zstd_compression_level on every request (including server hello)—settings ClickHouse rejects for that profile.

The server hello query now reads getSetting('readonly') and sets compressionSettings so codec/level settings are only applied when readonly ≠ 1 (readonly = 2 still gets configured compression). compress / decompress stay on all requests; read-only users rely on the server’s default codec.

applyNativeCompressionSettings is now a connection method and no longer overwrites network_compression_method or network_zstd_compression_level when they are already set in Options.Settings or per-query settings.

Integration tests cover read-only HTTP queries (LZ4/ZSTD/levels), settings precedence, and readonly = 2 behavior.

Reviewed by Cursor Bugbot for commit 23ce8db. Bugbot is set up for automated code reviews on this repo. Configure here.

Since v2.49.0 every HTTP request with LZ4 or ZSTD compression sets
network_compression_method, and network_zstd_compression_level for ZSTD
with a level. The server rejects a request that changes a setting for a
user with readonly = 1, so such a user could not open a connection when
the configured codec or level was not the server default.

The server hello query now reads the readonly setting and does not send
the two settings itself. Later requests send them only when the user can
change settings. compress and decompress are HTTP parameters and are
still sent for every user.

The two settings are also not replaced when the caller set them in
Options.Settings or for the query.
@kavirajk
kavirajk requested a review from a team as a code owner November 18, 2026 16:52
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
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.

HTTP: LZ4/ZSTD compression makes every query of a readonly=1 user fail with READONLY (regression in v2.49.0)

2 participants