Skip to content

fix(batch-exports): Handle cancellation of activities #31063

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
merged 2 commits into from
Apr 10, 2025

Conversation

rossgray
Copy link
Contributor

@rossgray rossgray commented Apr 10, 2025

Problem

Currently whenever batch export Temporal activities timeout or are cancelled the SPMC consumer task continues to run in the background. This consumes additional resources in ClickHouse and whatever external destination it is exporting data to.

Changes

Ensure the record batch consumer is cancelled if the activity itself is cancelled by Temporal.

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Extensive testing locally

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR improves cancellation handling in the batch exports system by implementing proper propagation of cancellation signals to all pending tasks.

  • Added asyncio.TaskGroup to manage consumer tasks, ensuring cancellation is properly propagated to all pending tasks
  • Modified Consumer.create_consumer_task() to accept a TaskGroup parameter instead of directly using asyncio.create_task()
  • Added cancellation detection in the consumer_done_callback function to log when a consumer task is cancelled
  • Restructured run_consumer() function to use TaskGroup for better cancellation handling and cleanup

Greptile AI

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@rossgray rossgray requested a review from tomasfarias April 10, 2025 14:24
@rossgray rossgray merged commit 8cb5ca3 into master Apr 10, 2025
97 checks passed
@rossgray rossgray deleted the batch-exports-handle-cancellations branch April 10, 2025 15:50
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.

2 participants