Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JobTimeoutException should be derived from BaseException instead of Exception #2296

@psrok1

Description

@psrok1

JobTimeoutException is derived from Exception which means that it can be mistakenly swallowed by the job function if it is doing it's own handling of unhandled exceptions.

def my_job(...) -> None:
    try:
        some_long_running_task()
    except Exception as e:
        handle_task_error(e)

Exception class is usually used for non-fatal exceptions caused directly by the application code. If you're injecting some exceptions via SIGALRM handling to indicate the need for ASAP finalization due to fatal error - BaseException is much better choice.

Actually that's pretty common problem e.g. https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.CancelledError used to be derived from Exception as well until 3.8. They changed that because some coroutines performing their own exception handling were uncancellable: https://bugs.python.org/issue32528

I would normally make a PR but I noticed that in some places rq is possibly catching JobTimeoutException using except Exception as well. I'm not very familiar with the exception flow in the code but I saw such handling in few places:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions