Skip to content

default_retry_delay does not work when enable_utc is False #3753

Closed

Description

@mabouels

Checklist

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
software -> celery:4.0.2 (latentcall) kombu:4.0.2 py:3.4.0
            billiard:3.5.0.2 redis:2.10.5
platform -> system:Linux arch:64bit, ELF imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost:6379/0

result_backend: 'redis://localhost:6379/0'
broker_url: 'redis://localhost:6379/0'
  • I have verified that the issue exists against the master branch of Celery.

Steps to reproduce

from celery import Celery
app = Celery('vanilla', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')

app.conf.enable_utc = False

@app.task(bind=True, max_retries=3, default_retry_delay=60)
def Fail(self):
    try:
        raise AssertionError('Oh My!')
    except Exception as e:
        self.retry(exc=e)

Expected behavior

A delay of around 60 seconds should happen between retries.

Actual behavior

The retry delay does not take any effect. This problem only occurs when enable_utc is set to False, as in the example above. The retry delay is however respected when enable_utc is left at its default value of True.

[2017-01-10 03:50:20,724: INFO/MainProcess] Received task: vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74]  
[2017-01-10 03:50:20,749: INFO/MainProcess] Received task: vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74]  ETA:[2017-01-10 03:51:20.727154+00:00] 
[2017-01-10 03:50:20,752: INFO/PoolWorker-4] Task vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74] retry: Retry in 60s: AssertionError('Oh My!',)
[2017-01-10 03:50:20,778: INFO/MainProcess] Received task: vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74]  ETA:[2017-01-10 03:51:20.755246+00:00] 
[2017-01-10 03:50:20,779: INFO/PoolWorker-5] Task vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74] retry: Retry in 60s: AssertionError('Oh My!',)
[2017-01-10 03:50:20,809: INFO/PoolWorker-2] Task vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74] retry: Retry in 60s: AssertionError('Oh My!',)
[2017-01-10 03:50:20,809: INFO/MainProcess] Received task: vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74]  ETA:[2017-01-10 03:51:20.783516+00:00] 
[2017-01-10 03:50:20,812: ERROR/PoolWorker-4] Task vanilla.Fail[8e3928ed-5a6a-4811-b2b6-c4b25ee51c74] raised unexpected: AssertionError('Oh My!',)
Traceback (most recent call last):
  File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 367, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 622, in __protected_call__
    return self.run(*args, **kwargs)
  File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 9, in Fail
    self.retry(exc=e)
  File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/task.py", line 668, in retry
    raise_with_context(exc)
  File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 7, in Fail
    raise AssertionError('Oh My!')
AssertionError: Oh My!

Activity

  1. mabouels commented on Jan 15, 2017

    @mabouels
    ContributorAuthor

    @georgepsarakis Yes, configuring a timezone when enable_utc is False works, but the retry delays are not respected. This issue is newly introduced in Celery 4+

  2. georgepsarakis commented on Jan 15, 2017

    @georgepsarakis
    Contributor

    I cannot reproduce it with Celery 4.0.2 either with Python 3.5.2 or Python 2.7.12 .

    What are your locale and timezone settings on the machine where you are running both worker and producer?

  3. mabouels commented on Jan 15, 2017

    @mabouels
    ContributorAuthor

    In the simplified example above, I am running both worker and producer on the same machine. I just tried setting the app.conf.timezone = 'US/Eastern', which is my machine's locale

    [2017-01-15 12:35:29,268: INFO/MainProcess] Connected to redis://localhost:6379/0
    [2017-01-15 12:35:29,276: INFO/MainProcess] mingle: searching for neighbors
    [2017-01-15 12:35:30,292: INFO/MainProcess] mingle: all alone
    [2017-01-15 12:35:30,300: INFO/MainProcess] celery@ott-ads-238 ready.
    [2017-01-15 12:35:36,367: INFO/MainProcess] Received task: vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf]  
    [2017-01-15 12:35:36,401: INFO/MainProcess] Received task: vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf]  ETA:[2017-01-15 07:36:36.369395-05:00] 
    [2017-01-15 12:35:36,408: INFO/PoolWorker-6] Task vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:35:36,431: INFO/MainProcess] Received task: vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf]  ETA:[2017-01-15 07:36:36.410458-05:00] 
    [2017-01-15 12:35:36,433: INFO/PoolWorker-2] Task vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:35:36,463: INFO/MainProcess] Received task: vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf]  ETA:[2017-01-15 07:36:36.438845-05:00] 
    [2017-01-15 12:35:36,467: INFO/PoolWorker-3] Task vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:35:36,469: ERROR/PoolWorker-6] Task vanilla.Fail[8cb5a597-7a3c-40b1-af82-187d56a4b1bf] raised unexpected: AssertionError('Oh My!',)
    Traceback (most recent call last):
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 367, in trace_task
        R = retval = fun(*args, **kwargs)
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 622, in __protected_call__
        return self.run(*args, **kwargs)
      File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 12, in Fail
        self.retry(exc=e)
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/task.py", line 668, in retry
        raise_with_context(exc)
      File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 10, in Fail
        raise AssertionError('Oh My!')
    AssertionError: Oh My!
    

    You can see that the ETA appearing in the logs are computed correctly, but not respected

  4. mabouels commented on Jan 15, 2017

    @mabouels
    ContributorAuthor

    For comparison purposes, when enable_utc is left to its default, the retry delay is respected

    from celery import Celery
    app = Celery('vanilla', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
    
    #app.conf.enable_utc = False
    #app.conf.timezone = 'US/Eastern'
    
    @app.task(bind=True, max_retries=3, default_retry_delay=60)
    def Fail(self):
        try:
            raise AssertionError('Oh My!')
        except Exception as e:
            self.retry(exc=e)
    
    [2017-01-15 12:42:59,162: INFO/MainProcess] Connected to redis://localhost:6379/0
    [2017-01-15 12:42:59,170: INFO/MainProcess] mingle: searching for neighbors
    [2017-01-15 12:43:00,292: INFO/MainProcess] mingle: all alone
    [2017-01-15 12:43:00,302: INFO/MainProcess] celery@ott-ads-238 ready.
    [2017-01-15 12:43:12,329: INFO/MainProcess] Received task: vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3]  
    [2017-01-15 12:43:12,355: INFO/MainProcess] Received task: vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3]  ETA:[2017-01-15 17:44:12.332357+00:00] 
    [2017-01-15 12:43:12,362: INFO/PoolWorker-5] Task vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:44:12,986: INFO/MainProcess] Received task: vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3]  ETA:[2017-01-15 17:45:12.962905+00:00] 
    [2017-01-15 12:44:12,998: INFO/PoolWorker-2] Task vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:45:13,805: INFO/MainProcess] Received task: vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3]  ETA:[2017-01-15 17:46:13.783278+00:00] 
    [2017-01-15 12:45:13,816: INFO/PoolWorker-6] Task vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3] retry: Retry in 60s: AssertionError('Oh My!',)
    [2017-01-15 12:46:14,085: ERROR/PoolWorker-5] Task vanilla.Fail[da51d8bf-61f1-4f2e-9e1f-3afe462acfa3] raised unexpected: AssertionError('Oh My!',)
    Traceback (most recent call last):
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 367, in trace_task
        R = retval = fun(*args, **kwargs)
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/trace.py", line 622, in __protected_call__
        return self.run(*args, **kwargs)
      File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 12, in Fail
        self.retry(exc=e)
      File "/auto/firex-ott/moe_4.0.2/lib/python3.4/site-packages/celery/app/task.py", line 668, in retry
        raise_with_context(exc)
      File "/auto/firex-ott/moe_4.0.2/vanilla.py", line 10, in Fail
        raise AssertionError('Oh My!')
    AssertionError: Oh My!
    
  5. georgepsarakis commented on Jan 15, 2017

    @georgepsarakis
    Contributor

    I think the app.now function should always return time in UTC. I think the bug is originating from here. What do you think?

  6. georgepsarakis commented on Jan 16, 2017

    @georgepsarakis
    Contributor

    Changing:

    now = now or self.app.now()

    to using UTC:

    from datetime import datetime
    now = now or datetime.utcnow()

    The retry behavior is correct again.

  7. mabouels commented on Jan 16, 2017

    @mabouels
    ContributorAuthor

    Yes, that seems to correct the retry behaviour. Thanks. Are you opening a PR @georgepsarakis

  8. georgepsarakis commented on Jan 16, 2017

    @georgepsarakis
    Contributor

    Well there are multiple points where a change could modify this behavior. For example here.

    Anyway, @mabouels since you discovered the bug I think it would be best if you opened the PR 😃 !

  9. georgepsarakis commented on Feb 11, 2017

    @georgepsarakis
    Contributor

    @mabouels will you open a PR for fixing this?

  10. mabouels commented on Feb 11, 2017

    @mabouels
    ContributorAuthor

    I am just not familiar enough with the code to fully understand the implications of the proposed fix.

  11. georgepsarakis commented on Feb 27, 2017

    @georgepsarakis
    Contributor

    @mabouels I think I managed to find a solution, check the linked PR.

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

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