Skip to content

fix: Add CancellationToken to Slack and remove unused IHttpClientFactory#1691

Merged
thomhurst merged 1 commit into
mainfrom
fix/http-improvements
Dec 30, 2025
Merged

fix: Add CancellationToken to Slack and remove unused IHttpClientFactory#1691
thomhurst merged 1 commit into
mainfrom
fix/http-improvements

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Added CancellationToken parameter to ISlack.PostWebHookMessage for proper cancellation support
  • Removed unused IHttpClientFactory parameter from Http.cs constructor

Changes

  • ISlack.cs: Added optional CancellationToken parameter to PostWebHookMessage
  • Slack.cs: Implemented cancellation token check in PostWebHookMessage
  • Http.cs: Removed unused IHttpClientFactory from constructor

Fixes #1547, Fixes #1583

Test plan

  • Build succeeds
  • Existing tests pass

🤖 Generated with Claude Code

…sed IHttpClientFactory (#1547, #1583)

- Add CancellationToken parameter to ISlack.PostWebHookMessage interface
- Update Slack implementation to accept and check CancellationToken
- Remove unused IHttpClientFactory parameter from Http class constructor

Fixes #1547, #1583

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

This PR adds CancellationToken support to the Slack webhook method and removes an unused IHttpClientFactory parameter from the Http class constructor.

Critical Issues

1. Incomplete CancellationToken implementation in Slack.PostWebHookMessage ⚠️

The PR adds a cancellationToken parameter and calls ThrowIfCancellationRequested() before creating the SlackClient, but the token is never passed to the actual slackClient.PostAsync() call:

public async Task PostWebHookMessage(SlackWebHookOptions options, CancellationToken cancellationToken = default)
{
    cancellationToken.ThrowIfCancellationRequested();
    
    var slackClient = new SlackClient(options.WebHookUri.AbsoluteUri, httpClient: _http.GetLoggingHttpClient());
    
    await slackClient.PostAsync(options.SlackMessage);  // ❌ Missing cancellationToken
}

This means:

  • The method will only check cancellation before making the HTTP request
  • The actual HTTP call to Slack cannot be cancelled once started
  • This defeats the purpose of adding CancellationToken support

Expected fix:
Check if the SlackClient.PostAsync() method supports a CancellationToken parameter. If it does, pass it:

await slackClient.PostAsync(options.SlackMessage, cancellationToken);

If the Slack.Webhooks library doesn't support cancellation tokens in PostAsync, then:

  • Either remove the early ThrowIfCancellationRequested() check (since it provides minimal value)
  • Or document this limitation in a comment explaining that cancellation only works before the HTTP call begins

Suggestions

IHttpClientFactory removal looks correct

The Http constructor parameter removal appears valid since:

  • The parameter was never assigned to a field
  • It's not used anywhere in the class
  • The class creates its own ServiceProvider with HttpClient internally (line 97-100 in Http.cs)

However, verify that:

  • All DI registrations were updated (no compilation errors)
  • The Http class is still properly instantiated throughout the codebase

Previous Review Status

Unable to access previous comments due to GitHub token scope limitations.

Verdict

⚠️ REQUEST CHANGES - The CancellationToken is not passed to the underlying async operation, making the implementation incomplete and potentially misleading.

@thomhurst thomhurst merged commit 875cee5 into main Dec 30, 2025
12 checks passed
@thomhurst thomhurst deleted the fix/http-improvements branch December 30, 2025 18:38
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.

Code smell: IHttpClientFactory injected but not used in Http class Code smell: Slack PostWebHookMessage does not accept CancellationToken

1 participant