ClickHouseConnection.CustomSettings writes change the shared client and the caller's settings object
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start in ClickHouse.Driver/ADO/ClickHouseConnection.cs at the CustomSettings property and the Settings setter, then follow how ClickHouseClient.cs keeps the settings by reference and reads CustomSettings around line 1044. Look at how ChangeDatabase in ClickHouseCommand.cs passes the database per request, as the model for a per-connection setting. Done means a write through one connection leaves the data source, other connections and the caller's ClickHouseClientSettings unchanged, and Clone() copies the connection's settings.
Written by the indexing model from the issue text.
Description
Describe the bug
ClickHouseConnection.CustomSettings returns the live CustomSettings dictionary of the connection's ClickHouseClient (ClickHouseConnection.cs#L161). The client keeps the settings object it gets by reference (ClickHouseClient.cs#L137) and reads that dictionary for each request (ClickHouseClient.cs#L1044).
All connections from one ClickHouseDataSource share one client. A write to CustomSettings on one connection therefore:
- applies to every other connection of the data source, and to
GetClient(); - changes the
ClickHouseClientSettingsobject that the caller gave to the data source.
The same occurs for connections made with new ClickHouseConnection(client) and with Clone().
There is no way to give one connection its own custom setting. The only alternative is to assign ClickHouseConnection.Settings, which replaces the connection's client with a new client and a new HTTP pool (ClickHouseConnection.cs#L182-L188).
Steps to reproduce
- Make a
ClickHouseDataSourcefrom aClickHouseClientSettingsobject. - Create two connections from it.
- Write a custom setting through the first connection.
- The second connection and the original settings object both contain the setting.
No server is necessary, because no query runs.
Expected behaviour
A setting written through one connection applies only to that connection. ChangeDatabase already works this way: the connection keeps the database itself and sends it with each request (ClickHouseCommand.cs#L252). The data source, its other connections and the caller's settings object do not change.
Code example
#:package [email protected]
using ClickHouse.Driver.ADO;
var userSettings = new ClickHouseClientSettings("Host=localhost");
using var dataSource = new ClickHouseDataSource(userSettings);
var a = dataSource.CreateConnection();
var b = dataSource.CreateConnection();
a.CustomSettings["join_use_nulls"] = "1";
Console.WriteLine(b.CustomSettings.ContainsKey("join_use_nulls")); // True
Console.WriteLine(userSettings.CustomSettings.ContainsKey("join_use_nulls")); // True
Suggested fix
Give each connection its own custom settings, and merge them between the client's settings and the command's settings when the command builds its request. The order is client, then connection, then command. Reading connection.CustomSettings should still show the client's settings, so that existing reads do not change. Clone() should copy the connection's database and custom settings.
This changes the result for code that writes connection.CustomSettings to configure every connection of a data source. If that use must continue to work, a new member can hold the per-connection settings, and CustomSettings can become obsolete.
Context
Found while working on ClickHouse.EntityFrameworkCore#50. The EF Core provider must add join_use_nulls to the connections it gets from a user's ClickHouseDataSource. A write to connection.CustomSettings would change the user's data source, so the provider assigns Settings instead, which builds a new client for each DbContext.
Configuration
Environment
- Client version: 1.5.0
- Language version: C# 14
- .NET version: 10.0
- OS: Linux
ClickHouse server
- Not needed. The defect occurs without a query.
- Dominant language
- C#
- Stars
- 102
- Forks
- 31
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/clickhouse-cs
-
bug documentation queries
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#815 ·
Maintainers usually reply within 1 day
-
bug data-types native-format
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-cs#813 ·
Maintainers usually reply within 1 day
-
bug data-types documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#811 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#809 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#806 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ClickHouse/clickhouse-cs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlPossibly taken @alexeyfala claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
danipen/TextMateSharp#145 · 2 comments ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Klyroo/klyroo-dashboard#12 ·
Maintainers usually reply within 1 day
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates onPossibly taken @yadavraj2001 claimed this today. Opendocumentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
juandresrodca/AdminForge#73 · 1 comment ·
Maintainers usually reply within 1 day
-
[辞書] VIVANTOpen要トリアージ 辞書
Difficulty 1/5 Under an hour Newbie friendliness 70/100
Maintainers usually reply within 1 day