Skip to content

Using Sentry SDK in worker leads to crash #261

@itssimon

Description

@itssimon

The Taskiq workers crash immediately if I initialise the Sentry SDK in the worker startup handler.

$ taskiq worker --ack-type when_executed --reload apitally.tasks:broker                                                                4s  cloud  base 20:37:47
[2023-12-11 20:40:48,284][taskiq.worker][INFO   ][MainProcess] Starting 2 worker processes.
[2023-12-11 20:40:48,284][root][WARNING][MainProcess] Reload on change enabled. Number of worker processes set to 1.
[2023-12-11 20:40:48,290][taskiq.process-manager][INFO   ][MainProcess] Started process worker-0 with pid 30331 
objc[30331]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[30331]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
[2023-12-11 20:40:50,301][taskiq.process-manager][INFO   ][MainProcess] worker-0 is dead. Scheduling reload.
[2023-12-11 20:40:51,314][taskiq.process-manager][INFO   ][MainProcess] Process worker-0 restarted with pid 30338
objc[30338]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[30338]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
[2023-12-11 20:40:53,330][taskiq.process-manager][INFO   ][MainProcess] worker-0 is dead. Scheduling reload.
[2023-12-11 20:40:54,338][taskiq.process-manager][INFO   ][MainProcess] Process worker-0 restarted with pid 30342
objc[30342]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[30342]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

The worker startup handler looks like this:

@broker.on_event(TaskiqEvents.WORKER_STARTUP)
async def on_worker_startup(state: TaskiqState) -> None:
    sentry_sdk.init(
        dsn=str(settings.sentry_dsn),
        environment=settings.sentry_environment,
    )

This doesn't happen if I don't use Sentry, or if I start the worker without the --reload flag.

Environment:

  • macOS 14.0 (Sonoma)
  • Python 3.11
  • taskiq 0.10.4
  • sentry-sdk 1.38.0

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