Skip to content

Implement ClickHouseRawResult cancellation APIs - #605

Open
Skyuzii wants to merge 1 commit into
ClickHouse:mainfrom
Skyuzii:raw_result_reader_cancellation_api
Open

Implement ClickHouseRawResult cancellation APIs#605
Skyuzii wants to merge 1 commit into
ClickHouse:mainfrom
Skyuzii:raw_result_reader_cancellation_api

Conversation

@Skyuzii

@Skyuzii Skyuzii commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #546

Implement ClickHouseRawResult cancellation APIs

Warning: A test for passing a cancelled token to ReadAsStreamAsync was not added, as it is ignored in .NET. - Link

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

Copilot AI lite review requested due to automatic review settings August 31, 2026 23:32
@Skyuzii
Skyuzii requested a review from mzitnik as a code owner August 31, 2026 23:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds cancellation-token overloads to ClickHouseRawResult read/copy APIs so callers can cancel ReadAsStringAsync, ReadAsByteArrayAsync, stream reads, decompressed-stream reads, and CopyToAsync, aligning the raw-result surface with typical .NET async cancellation patterns.

Changes:

  • Added CancellationToken overloads for ReadAsStreamAsync, ReadDecompressedStreamAsync, ReadAsByteArrayAsync, ReadAsStringAsync, and CopyToAsync on ClickHouseRawResult.
  • Expanded ADO test coverage to validate the new overloads and canceled-token behavior for buffering/copying operations.
  • Added a changelog fragment for issue #546.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ClickHouse.Driver/ADO/Readers/ClickHouseRawResult.cs Adds cancellation-token overloads for raw result reading/copying APIs.
ClickHouse.Driver.Tests/ADO/RawResultReaderAsyncTests.cs Adds/renames tests to cover new cancellation overloads and cancellation behavior.
ClickHouse.Driver.Tests/ADO/ClickHouseRawResultDecompressionTests.cs Adds cancellation-related tests for decompressed stream reads.
changelog.d/546-raw-result-reader-cancellation-api.improvements.md Changelog fragment documenting the user-facing improvement.
Suppressed comments (1)

ClickHouse.Driver/ADO/Readers/ClickHouseRawResult.cs:130

  • ReadDecompressedStreamAsync(CancellationToken) currently relies on HttpContent.ReadAsStreamAsync(cancellationToken) for cancellation. If that underlying overload ignores cancellation, this method won’t honor an already-canceled token (and the added test that expects OperationCanceledException becomes unreliable). Add an explicit pre-check before acquiring/wrapping the content stream.
        if (decompressedStream != null)
            return decompressedStream;

        var rawStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to the response content stream.</returns>
public Task<Stream> ReadAsStreamAsync(CancellationToken cancellationToken) => response.Content.ReadAsStreamAsync(cancellationToken);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to keep the standard BCL behavior

Comment thread ClickHouse.Driver/ADO/Readers/ClickHouseRawResult.cs
Comment thread ClickHouse.Driver.Tests/ADO/RawResultReaderAsyncTests.cs Outdated
return decompressedStream;

var rawStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var rawStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancelled token ignored on stream reads

Medium Severity

ReadDecompressedStreamAsync only forwards the token to ReadAsStreamAsync, which this PR notes the BCL ignores for a cancelled token, and never checks the token itself. A cancelled token still returns a stream. The new unit test expects OperationCanceledException and will fail against ByteArrayContent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 42e4237. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to keep the standard BCL behavior

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 46a60eb. Configure here.

Comment thread ClickHouse.Driver/PublicAPI/PublicAPI.Unshipped.txt Outdated
@Skyuzii
Skyuzii force-pushed the raw_result_reader_cancellation_api branch from b08c2ba to b3223f8 Compare September 1, 2026 14:39
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.

ClickHouseRawResult.ReadAsStringAsync (and friends) should support cancellation

2 participants