Repository navigation
Fix ADO.NET: apply CommandTimeout as max_execution_time #619
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
Merged
alex-clickhouse
merged 4 commits into
main
from
polyglot/command-timeout-max-execution-time
Sep 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7eec06d
Fix ADO.NET: apply CommandTimeout as max_execution_time
polyglotAI-bot f2ba61c
Narrow CommandTimeout docs to positive values
polyglotAI-bot ac372b2
Merge remote-tracking branch 'origin/main' into polyglot/command-time…
polyglotAI-bot 212e037
Shorten CommandTimeout comments and docs
alex-clickhouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using ClickHouse.Driver.ADO; | ||
|
|
||
| namespace ClickHouse.Driver.Tests.ADO; | ||
|
|
||
| public class CommandTimeoutTests : AbstractConnectionTestFixture | ||
| { | ||
| public enum ExecutionPath | ||
| { | ||
| Scalar, | ||
| NonQuery, | ||
| Reader, | ||
| RawResult, | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecuteScalarAsync_WithCommandTimeout_AppliesMaxExecutionTimeSetting() | ||
| { | ||
| using var command = connection.CreateCommand("SELECT getSetting('max_execution_time')"); | ||
| command.CommandTimeout = 30; | ||
|
|
||
| Assert.That(await command.ExecuteScalarAsync(), Is.EqualTo(30UL)); | ||
| } | ||
|
|
||
| [TestCase(ExecutionPath.Scalar)] | ||
| [TestCase(ExecutionPath.NonQuery)] | ||
| [TestCase(ExecutionPath.Reader)] | ||
| [TestCase(ExecutionPath.RawResult)] | ||
| public void ExecuteAsync_WithCommandTimeout_LongQueryIsCancelledByServer(ExecutionPath path) | ||
| { | ||
| using var command = connection.CreateCommand("SELECT sleep(3)"); | ||
| command.CommandTimeout = 1; | ||
|
|
||
| var ex = Assert.ThrowsAsync<ClickHouseServerException>(async () => await ExecuteAsync(command, path)); | ||
|
|
||
| // TIMEOUT_EXCEEDED = 159 | ||
| Assert.That(ex!.ErrorCode, Is.EqualTo(159)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecuteScalarAsync_WithDefaultCommandTimeout_LeavesMaxExecutionTimeUnchanged() | ||
| { | ||
| var serverDefault = await client.ExecuteScalarAsync("SELECT getSetting('max_execution_time')"); | ||
|
|
||
| using var command = connection.CreateCommand("SELECT getSetting('max_execution_time')"); | ||
|
|
||
| Assert.That(await command.ExecuteScalarAsync(), Is.EqualTo(serverDefault)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecuteScalarAsync_WithNegativeCommandTimeout_LeavesMaxExecutionTimeUnchanged() | ||
| { | ||
| var serverDefault = await client.ExecuteScalarAsync("SELECT getSetting('max_execution_time')"); | ||
|
|
||
| using var command = connection.CreateCommand("SELECT getSetting('max_execution_time')"); | ||
| command.CommandTimeout = -1; | ||
|
|
||
| Assert.That(await command.ExecuteScalarAsync(), Is.EqualTo(serverDefault)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecuteScalarAsync_WithCommandTimeoutAndCommandCustomSetting_PrefersCustomSetting() | ||
| { | ||
| using var command = connection.CreateCommand("SELECT getSetting('max_execution_time')"); | ||
| command.CommandTimeout = 30; | ||
| command.CustomSettings.Add("max_execution_time", 45); | ||
|
|
||
| Assert.That(await command.ExecuteScalarAsync(), Is.EqualTo(45UL)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecuteScalarAsync_WithCommandTimeoutAndConnectionCustomSetting_PrefersCommandTimeout() | ||
| { | ||
| var builder = TestUtilities.GetConnectionStringBuilder(); | ||
| builder["set_max_execution_time"] = 45; | ||
| using var connectionWithSetting = new ClickHouseConnection(builder.ConnectionString); | ||
|
|
||
| using var command = connectionWithSetting.CreateCommand("SELECT getSetting('max_execution_time')"); | ||
| command.CommandTimeout = 30; | ||
|
|
||
| Assert.That(await command.ExecuteScalarAsync(), Is.EqualTo(30UL)); | ||
| } | ||
|
|
||
| private static async Task ExecuteAsync(ClickHouseCommand command, ExecutionPath path) | ||
| { | ||
| switch (path) | ||
| { | ||
| case ExecutionPath.Scalar: | ||
| await command.ExecuteScalarAsync(); | ||
| break; | ||
| case ExecutionPath.NonQuery: | ||
| await command.ExecuteNonQueryAsync(); | ||
| break; | ||
| case ExecutionPath.Reader: | ||
| using (var reader = await command.ExecuteReaderAsync()) | ||
| { | ||
| while (await reader.ReadAsync()) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| break; | ||
| case ExecutionPath.RawResult: | ||
| using (await command.ExecuteRawResultAsync(default)) | ||
| { | ||
| } | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| * Fixed `ClickHouseCommand.CommandTimeout` being ignored ([#618](https://github.com/ClickHouse/clickhouse-cs/issues/618)). | ||
| A non-zero value is now sent as the `max_execution_time` setting, so the server cancels a query | ||
|
polyglotAI-bot marked this conversation as resolved.
Resolved
|
||
| that exceeds it. Zero, the default, still means no limit, and an explicit `max_execution_time` in | ||
| the command's `CustomSettings` takes precedence. | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.