-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Task is executed twice when the worker restarts #4426
Comments
not sure if it's an issue of celery. try the newer release and report it again, if seems to be a celery issue |
Having the same issue, tasks with eta get executed multiple times after restart of the worker. I've increased processes on my virtual machine, and celery created worker with concurrency of 2(had 1 before). |
This bug should be re-opened. at $DAY_JOB we are seeing this error every time we deploy(restart). cc @auvipy |
Hi @canassa and @imomaliev did either of you manage to fix this issue on your end? I would appreciate any workarounds that you may have. |
@komuw My workaround was similar to what I posted in the issue description, I used a cache key with the request id to detect duplicated tasks and dropped them. We never found a fix issue for issue but it was very easy to reproduce by following the steps that I provided. I have long since left the company where this issue was occurring so I am not checking this problem anymore. |
thanks |
Found the issue seems like celery is using a promise to acknowledge. meaning during a restart when the rabbitmq connection fails it won't ack but still process the task will be returned back to ready and processed later on again |
To fix patch request object with this in proj/celery.py from celery.worker.request import Request
# making acknowledgment to be synchronous
# instead of using promise
def new_acknowledge(self):
"""Acknowledge task."""
if not self.acknowledged:
self.message.ack()
self.acknowledged = True
Request.acknowledge = new_acknowledge |
Hi @auvipy
Would you be willing to accept a pull request to celery with such a fix as
has been laid out above by my colleague @mwaaas ?
Basically, acknowledgements in celery-gevent should still happen
synchronously instead of asynchronously.
On Fri, 12 Jul 2019 at 16:32, Francis Mwangi ***@***.***> wrote:
To fix patch request object with this
from celery.worker.request import Request# making acknowledgment to be synchronous# instead of using promise
Request.acknowledge = lambda self: self.message.ack()
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4426?email_source=notifications&email_token=ABHMWUNZDSY6MIABAKNTCYLP7CBVPA5CNFSM4EHOPEL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZZYMNQ#issuecomment-510887478>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABHMWUIGFOCTWH75EMHO5PLP7CBVPANCNFSM4EHOPELQ>
.
--
Thanks,
KomuW.
https://www.komu.engineer/about
|
Currently using Celery 4.1.0
Steps to reproduce
Start a new project using RabbitMQ and register the following task:
Now start 2 workers. I used gevent with a concurrency of 25 for this test:
Open a python shell and fire a a bunch of tasks:
Now quickly do a warm shutdown (Ctrl+c) in one of the workers while it's still processing the tasks, you should see the errors popping in the second worker:
Expected behavior
Since I am not using late acknowledgment and I am not killing the workers I wasn't expecting the tasks to execute again.
Actual behavior
The tasking are being executed twice, this is causing some problems in our servers because we restart our works every 15 minutes or so in order to avoid memory leaks.
The text was updated successfully, but these errors were encountered: