Skip to content

fix: clean up async consumer waiters on cancellation - #940

Merged
marandaneto merged 1 commit into
PostHog:mainfrom
nickita-khylkouski:fix/async-consumer-cancellation
Sep 11, 2026
Merged

marandaneto merged 1 commit into
PostHog:mainfrom
nickita-khylkouski:fix/async-consumer-cancellation

Conversation

@nickita-khylkouski

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Cancelling _get_or_flush while it is inside asyncio.wait can leave its queue and flush helper tasks pending. Put the wait in try/finally, cancel any unfinished helper tasks, and gather both before propagating cancellation.

💚 How did you test it?

  • Full test suite: 2,488 passed, 15 skipped, 38 subtests passed
  • Full mypy check: 230 source files, no issues
  • Import smoke test and package build
  • Added cancellation and result-preservation coverage for _get_or_flush and the worker path

The repository-wide Ruff command currently reports existing formatting and legacy-lint findings in untouched files; the modified Python files pass formatting.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

An equivalent patch changeset is included at .sampo/changesets/async-consumer-cancellation.md.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

The contributor directed the scope and exact cleanup behavior. Codex helped inspect the repository, apply the bounded change, and run the repository checks; the implementation cancels only unfinished waiter tasks and gathers both to avoid leaked-task warnings.

@nickita-khylkouski
nickita-khylkouski requested a review from a team as a code owner September 10, 2026 16:11
@marandaneto

Copy link
Copy Markdown
Member

thanks @nickita-khylkouski

@marandaneto
marandaneto force-pushed the fix/async-consumer-cancellation branch from a3feb50 to aeb4f45 Compare September 11, 2026 08:17
@marandaneto
marandaneto enabled auto-merge (squash) September 11, 2026 08:18
@marandaneto
marandaneto merged commit dadd278 into PostHog:main Sep 11, 2026
41 checks passed
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