Skip to content

--hardkill-count appears off by one #647

Description

@aysanorhun

Taskiq version

0.12.4

Python version

Python 3.12

OS

Linux

What happened?

Description

The documentation describes --hardkill-count as the number of termination signals allowed before performing a hardkill.

However, the counter is currently implemented as:

hardkill_counter = 0

def interrupt_handler(signum, _frame):
    nonlocal hardkill_counter

    shutdown_event.set()

    if hardkill_counter > args.hardkill_count:
        logger.warning("Hard kill. Exiting.")
        raise KeyboardInterrupt

    hardkill_counter += 1

Because the comparison happens before incrementing and uses >, --hardkill-count 3 behaves as follows:

Signal Counter before signal Result
1 0 Graceful shutdown
2 1 Graceful shutdown
3 2 Graceful shutdown
4 3 Graceful shutdown
5 4 Hardkill

If the value means “three termination signals before hardkill,” I would expect the fourth signal to trigger the hardkill. The current implementation triggers it on the fifth signal.

Would this condition be expected to use >= instead?

if hardkill_counter >= args.hardkill_count:
    logger.warning("Hard kill. Exiting.")
    raise KeyboardInterrupt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions