-
Notifications
You must be signed in to change notification settings - Fork 11
Fix connecting via SenderOptions.addr #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,8 @@ public record SenderOptions | |
| "pool_timeout", "tls_verify", "tls_roots", "tls_roots_password", "own_socket", "gzip", | ||
| }; | ||
|
|
||
| private string _addr = "localhost:9000"; | ||
| private List<string> _addresses = new(); | ||
| private const string DefaultAddress = "localhost:9000"; | ||
| private readonly List<string> _addresses = new(); | ||
|
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and examine the SenderOptions.cs file
fd -t f "SenderOptions.cs" --type fRepository: questdb/net-questdb-client Length of output: 115 🏁 Script executed: # Get the file size and structure
wc -l src/net-questdb-client/Utils/SenderOptions.csRepository: questdb/net-questdb-client Length of output: 119 🏁 Script executed: # Check the record declaration and key lines
sed -n '1,70p' src/net-questdb-client/Utils/SenderOptions.csRepository: questdb/net-questdb-client Length of output: 2817 🏁 Script executed: # Check the addr property (around lines 162-167)
sed -n '160,175p' src/net-questdb-client/Utils/SenderOptions.csRepository: questdb/net-questdb-client Length of output: 529 🏁 Script executed: # Check the WithClientCert method (around line 731)
sed -n '725,740p' src/net-questdb-client/Utils/SenderOptions.csRepository: questdb/net-questdb-client Length of output: 380 🏁 Script executed: # Search for all 'with' expressions in C# files
rg -nP --type=cs '\bwith\s*\{' --glob '!**/obj/**' --glob '!**/bin/**'Repository: questdb/net-questdb-client Length of output: 214 🏁 Script executed: # Check how many lines the file has and look at the end for any relevant code
tail -20 src/net-questdb-client/Utils/SenderOptions.csRepository: questdb/net-questdb-client Length of output: 525 🏁 Script executed: # Verify field initializer behavior in records and check if there's any evidence of actual mutations
rg -nP --type=cs '_addresses' src/net-questdb-client/Utils/SenderOptions.cs -B2 -A2Repository: questdb/net-questdb-client Length of output: 1477 🏁 Script executed: # Check if there are usages of WithClientCert in tests or elsewhere that might expose the bug
rg -nP --type=cs 'WithClientCert' --glob '!**/obj/**' --glob '!**/bin/**' -B3 -A3Repository: questdb/net-questdb-client Length of output: 1297 🏁 Script executed: # Check what tests exist and if they might be hitting this aliasing issue
rg -nP --type=cs '\.addr\s*=' --glob '!**/obj/**' --glob '!**/bin/**' -B2 -A2Repository: questdb/net-questdb-client Length of output: 520 Mutable
Applies to lines 60 (field declaration), 162-167 (addr property), and 729-733 (WithClientCert). Recommended fixes:
🤖 Prompt for AI Agents |
||
| private TimeSpan _authTimeout = TimeSpan.FromMilliseconds(15000); | ||
| private AutoFlushType _autoFlush = AutoFlushType.on; | ||
| private int _autoFlushBytes = int.MaxValue; | ||
|
|
@@ -91,7 +91,7 @@ public record SenderOptions | |
| /// </summary> | ||
| public SenderOptions() | ||
| { | ||
| ParseAddresses(); | ||
| addr = DefaultAddress; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -103,8 +103,6 @@ public SenderOptions(string confStr) | |
| ReadConfigStringIntoBuilder(confStr); | ||
| ParseEnumWithDefault(nameof(protocol), "http", out _protocol); | ||
| ParseEnumWithDefault(nameof(protocol_version), "auto", out _protocol_version); | ||
| ParseStringWithDefault(nameof(addr), "localhost:9000", out _addr!); | ||
| ParseAddresses(); | ||
| ParseEnumWithDefault(nameof(auto_flush), "on", out _autoFlush); | ||
| ParseIntThatMayBeOff(nameof(auto_flush_rows), IsHttp() ? "75000" : "600", out _autoFlushRows); | ||
| ParseIntThatMayBeOff(nameof(auto_flush_bytes), int.MaxValue.ToString(), out _autoFlushBytes); | ||
|
|
@@ -161,8 +159,12 @@ public ProtocolVersion protocol_version | |
| /// </remarks> | ||
| public string addr | ||
| { | ||
| get => _addr; | ||
| set => _addr = value; | ||
| get => _addresses[0]; | ||
| set | ||
| { | ||
| _addresses.Clear(); | ||
| _addresses.Add(value); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -595,21 +597,25 @@ private void ReadConfigStringIntoBuilder(string confStr) | |
| // Parse addresses manually before using DbConnectionStringBuilder | ||
| // because DbConnectionStringBuilder only keeps the last value for duplicate keys | ||
| _addresses.Clear(); | ||
| foreach (var param in paramString.Split(';')) | ||
| foreach (var param in paramString.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(param)) continue; | ||
| if (!param.StartsWith("addr", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var kvp = param.Split('='); | ||
| if (kvp.Length == 2 && kvp[0].Trim() == "addr") | ||
| var kvp = param.Split('=', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); | ||
| if (kvp.Length == 2 && kvp[0].Equals("addr", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| var addrValue = kvp[1].Trim(); | ||
| if (!string.IsNullOrEmpty(addrValue)) | ||
| { | ||
| _addresses.Add(addrValue); | ||
| } | ||
| _addresses.Add(kvp[1]); | ||
| } | ||
| } | ||
|
|
||
| if (_addresses.Count == 0) | ||
| { | ||
| _addresses.Add(DefaultAddress); | ||
| } | ||
|
|
||
| _connectionStringBuilder = new DbConnectionStringBuilder | ||
| { | ||
| ConnectionString = paramString, | ||
|
|
@@ -704,15 +710,6 @@ private void VerifyCorrectKeysInConfigString() | |
| } | ||
| } | ||
|
|
||
| private void ParseAddresses() | ||
| { | ||
| // If no addresses were parsed from config string, use the primary addr | ||
| if (_addresses.Count == 0) | ||
| { | ||
| _addresses.Add(_addr); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Construct a new <see cref="ISender" /> from the current options. | ||
| /// </summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is at odds with how
addris documented ("When multiple addresses are configured, this returns the first one."). So either the test needs to change or addr does. Went with the former