Skip to content

fix(scheduler): clean up started sources when startup fails - #672

Open
stupidprogrammer4 wants to merge 1 commit into
taskiq-python:masterfrom
stupidprogrammer4:fix/scheduler-startup-cleanup
Open

stupidprogrammer4 wants to merge 1 commit into
taskiq-python:masterfrom
stupidprogrammer4:fix/scheduler-startup-cleanup

Conversation

@stupidprogrammer4

Copy link
Copy Markdown

When source A starts successfully and source B raises during run_scheduler() startup, A's shutdown() hook is never called. The same omission occurs if all sources start but scheduler/broker startup fails.

Track sources whose startup completed and shut them down in reverse order on startup failure or cancellation. Log individual cleanup failures, continue closing the remaining started sources, and re-raise the original startup exception. Do not call shutdown on the source or scheduler whose startup failed. Normal loop cancellation and shutdown ordering are preserved.

Validation:

  • Seven regression cases fail on the unmodified upstream c4b8666 checkout; the two boundary/normal-shutdown cases already pass.
  • All nine new cases pass after the fix, including actual task cancellation during source startup, scheduler startup failures, and exceptions from cleanup hooks.
  • Linux / CPython 3.13.1, dependencies from uv.lock with all extras: pytest -q -n 2 --tb=short — 355 passed.
  • Focused CLI, scheduler, and scheduler API suite — 88 passed.
  • All applicable pre-commit hooks pass on both changed files, including repository-wide Ruff and mypy checks.

This fixes a missing lifecycle callback; no production leak or data loss is claimed. A component remains responsible for resources acquired during its own failed startup. Scheduler-loop errors and draining running tasks are outside this change; #671 addresses loop-owned task draining separately.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.71%. Comparing base (c4b8666) to head (9835983).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #672      +/-   ##
==========================================
+ Coverage   82.63%   82.71%   +0.07%     
==========================================
  Files          69       69              
  Lines        2730     2742      +12     
==========================================
+ Hits         2256     2268      +12     
  Misses        474      474              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant