Skip to content

CeleryIntegration with Redbeat scheduler seems to send 2 In Progress Check ins leading 1 to Timeout #4392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Fwang36 opened this issue May 14, 2025 · 9 comments · Fixed by #4395

Comments

@Fwang36
Copy link
Member

Fwang36 commented May 14, 2025

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.28.0

Steps to Reproduce

Helping a user in this Zendesk ticket (last several responses): https://sentry.zendesk.com/agent/tickets/152175

It seems like the celery integration used with the Redbeat scheduler is creating two in-progress check in events at the scheduled time. The worker only sends 1 OK check-in event leading to the other in-progress event to timeout. I was able to reproduce this with a task that runs every minute.

Using the celery beat scheduler instead of redbeat works as expected.

My sentry settings -

@signals.beat_init.connect
@signals.celeryd_init.connect
def init_sentry(**_kwargs):
    sentry_sdk.init(
        dsn="<DSN>",
        send_default_pii=True,
        integrations=[CeleryIntegration(
            monitor_beat_tasks=True,
        )],
        debug=True,
    )

Run commands -

celery -A tasks worker --loglevel=INFO
celery -A tasks beat --scheduler redbeat.RedBeatScheduler --loglevel=INFO

When the task starts, I get 2 monitor check ins per every time the task is run (task runs 2 times in screenshot) in beat terminal -

Image

In the worker terminal, I get 1 check in per task (as expected) -

Image

In the UI, it looks like this, where the In Progress check ins will then timeout after the set threshold -

Image

Link to my monitor

Expected Result

Sends only 1 in progress event when the task begins.

Expect behavior to match celery beat scheduler

Actual Result

Sends 2 in progress events when the task begins.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 14, 2025
@Fwang36 Fwang36 changed the title CeleryIntegration with Redbeat scheduler seems to send 2 In Progress Check ins CeleryIntegration with Redbeat scheduler seems to send 2 In Progress Check ins leading 1 to Timeout May 14, 2025
@antonpirker
Copy link
Member

Hey @Fwang36 thanks for the great issue description! I will have a look

@antonpirker
Copy link
Member

I have now reproduced your error:

  • The beat task sends a in_progress for my task with the checkin-id a.
  • Then the celery process sends a in_progress for my task with the checkin-id b,
  • then a ok checkin with checkin-id b,
  • and finally a ok checkin with checkin-id a.

That is the project I used: https://github.com/antonpirker/testing-sentry/tree/main/test-celery-redbeat

So clearly something is off. I prioritize this fix. I'll keep you posted, sometime next we should have this fixed.

@antonpirker
Copy link
Member

Here my beat log:

Image

Here my celery worker log:

Image

@antonpirker
Copy link
Member

antonpirker commented May 15, 2025

I have now tested by disabling celery-redbeat in my test project, using the default celery scheduler (celery.beat.PersistentScheduler) and I get the same result. So this issue is affecting more people then just redbeat users.

@sentrivana
Copy link
Contributor

This looks like possible double instrumentation to me.

Is it possible you're using both monitor_beat_tasks=True and wrapping the tasks in the @sentry_sdk.monitor decorator? They are mutually exclusively per my understanding -- i.e., you either let Sentry monitor all beat tasks automagically, or you let it monitor none and you hand-pick whichever you want with the decorator.

@sentrivana
Copy link
Contributor

Nevermind, I get the extra in_progress check-in too. Looking into this.

Copy link
Contributor

sentrivana commented May 16, 2025

As far as I can tell, the problem is that we're patching redbeat's maybe_due and sending an in-progress check-in there, even though maybe_due might not end up actually scheduling the task if it determines it's not supposed to run. Fix here: #4395

We can cut a release with this next week.

@antonpirker
Copy link
Member

Small related docs update: getsentry/sentry-docs#13751

sentrivana added a commit that referenced this issue May 19, 2025
When using the RedBeatScheduler, we're sending an extra in-progress
check-in at scheduler start. Since this is never followed by an ok or
error check-in, the check-in is marked as timed out in Sentry.

We're patching the scheduler's `maybe_due`, which (as the name implies)
[might not end up executing the
task](https://github.com/sibson/redbeat/blob/bdefad23b47f75e2e85d45f46f9f16dd00a93d40/redbeat/schedulers.py#L506-L508).
This is indeed what seems to be happening -- `maybe_due` is run when the
scheduler starts, but without scheduling the task. We don't check
whether `maybe_due` actually ended up scheduling anything and always
fire an in-progress check-in.

Patching the [scheduler's
`apply_async`](https://github.com/sibson/redbeat/blob/bdefad23b47f75e2e85d45f46f9f16dd00a93d40/redbeat/schedulers.py#L511)
instead.

Closes #4392
@sentrivana
Copy link
Contributor

The fix for this is now out in 2.29.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants