Skip to content

fix(cli): correct --hardkill-count off-by-one in worker signal handler#648

Open
gitcommit90 wants to merge 1 commit into
taskiq-python:masterfrom
gitcommit90:fix/issue-647-hardkill-count-off-by-one
Open

fix(cli): correct --hardkill-count off-by-one in worker signal handler#648
gitcommit90 wants to merge 1 commit into
taskiq-python:masterfrom
gitcommit90:fix/issue-647-hardkill-count-off-by-one

Conversation

@gitcommit90

Copy link
Copy Markdown

Summary

Fixes #647: --hardkill-count N was off by one in the worker signal handler.

Docs/CLI help describe N as the number of termination signals allowed before a hard kill (hard kill on signal N+1). The handler compared hardkill_counter > args.hardkill_count before incrementing, so with the default N=3 the hard kill fired on the 5th signal instead of the 4th.

Changes

  • taskiq/cli/worker/run.py: change > to >= so hard kill runs on signal N+1.
  • Add tests/cli/worker/hanging_broker.py and tests/cli/worker/test_hardkill_count.py — integration test that spawns a real worker with a broker whose graceful shutdown hangs, sends SIGINTs to the worker child, and asserts survival through N signals and hard kill on N+1.

Test plan

  • New hardkill-count integration test fails on pre-fix code and passes with the fix
  • Full suite: pytest tests/ -q -n auto → 298 passed
  • ruff check, ruff format --check, black --check, mypy clean on touched files

Closes #647

The worker's interrupt handler compared hardkill_counter to
args.hardkill_count with '>' before incrementing, so N allowed
termination signals actually required N+2 signals to hard-kill
(e.g. the default --hardkill-count 3 hard-killed on the 5th signal).

Use '>=' so signal N+1 performs the hard kill, matching the CLI help
text: 'Number of termination signals to the main process before
performing a hardkill.'

Add an integration test that spawns a real worker with a broker whose
graceful shutdown hangs, sends SIGINTs to the worker child process,
and asserts the worker survives N signals and is hard-killed on
signal N+1. The test fails on the previous comparison and passes
with this fix.

Fixes taskiq-python#647
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.

--hardkill-count appears off by one

1 participant