Skip to content

Nested chords bug(s) when using redis as result_backend #3538

Closed

Description

@bruno-rino

Disclaimer: There might be two independent bugs, or maybe the same bug causes both behaviours.

When using redis as result_backend to execute a canvas with nested chords, I find these behaviours:

  • when there are two parallel "tasks" on the main chord's head: the main chord's body and subsequent tasks are executed twice.
  • when there are three parallel "tasks" on the main chord's head: the main chord's body is not executed, and the client hangs.

Using amqp as result_backend or with task_always_eager=True I get a correct execution.

Steps to reproduce

The following code defines 6 canvases: the first three have two parallel "tasks" on the main chord's head, the remaining three have three parallel "tasks".

I wrote the canvas three times using different syntax (using chord; chain and group; group and | ), but the result is consistent. I keep all of them in this bug report because I don't know which syntax I should prefer when reporting bugs.

from __future__ import absolute_import, division, print_function
from celery import Celery, group, chain, chord
import time

app = Celery('deep')
app.config_from_object({
    # 'broker_url': 'redis://',
    # 'result_backend': 'redis',
    'broker_url': 'amqp://',
    'result_backend': 'redis://localhost',
    # 'result_backend': 'amqp',
    # 'result_backend': 'rpc://',
    'task_always_eager': False,
})


@app.task(bind=True)
def echo(self, name):
    print(name)
    return name


if __name__ == '__main__':
    mytasks_implicit = chain([
        echo.si('-> implicit chord'),
        group([
            chain([
                group([
                    chain([group([echo.si('111'), echo.si('112'), ]), echo.si('11_'), ]),
                    chain([group([echo.si('121'), echo.si('122'), ]), echo.si('12_'), ]),
                ]), echo.si('1_'),
            ]),
            chain([
                group([
                    chain([group([echo.si('211'), echo.si('212'), ]), echo.si('21_'), ]),
                    chain([group([echo.si('221'), echo.si('222'), ]), echo.si('22_'), ]),
                ]), echo.si('2_'),
            ]),
        ]),
        echo.si('_'),
        echo.si('#'),
        echo.si('$'),
    ])

    mytasks_explicit = chain([
        echo.si('-> explicit chord'),
        chord([
            chord([
                chord([echo.si('111'), echo.si('112'), ], body=echo.si('11_')),
                chord([echo.si('121'), echo.si('122'), ], body=echo.si('12_')),
            ], body=echo.si('1_')),
            chord([
                chord([echo.si('211'), echo.si('212'), ], body=echo.si('21_')),
                chord([echo.si('221'), echo.si('222'), ], body=echo.si('22_')),
            ], body=echo.si('2_')),
        ], body=echo.si('_')),
        echo.si('#'),
        echo.si('$'),
    ])

    mytasks_or_operator = echo.si('-> or operator') | group([
        group([
            group([echo.si('111'), echo.si('112'), ]) | echo.si('11_'),
            group([echo.si('121'), echo.si('122'), ]) | echo.si('12_'),
        ]) | echo.si('1_'),
        group([
            group([echo.si('211'), echo.si('212'), ]) | echo.si('21_'),
            group([echo.si('221'), echo.si('222'), ]) | echo.si('22_'),
        ]) | echo.si('2_'),
    ]) | echo.si('_') | echo.si('#') | echo.si('$')

    mytasks_implicit_3 = chain([
        echo.si('-> implicit chord (3)'),
        group([
            chain([
                group([
                    chain([group([echo.si('111'), echo.si('112'), ]), echo.si('11_'), ]),
                    chain([group([echo.si('121'), echo.si('122'), ]), echo.si('12_'), ]),
                ]), echo.si('1_'),
            ]),
            chain([
                group([
                    chain([group([echo.si('211'), echo.si('212'), ]), echo.si('21_'), ]),
                    chain([group([echo.si('221'), echo.si('222'), ]), echo.si('22_'), ]),
                ]), echo.si('2_'),
            ]),
            chain([
                group([
                    chain([group([echo.si('311'), echo.si('312'), ]), echo.si('31_'), ]),
                    chain([group([echo.si('321'), echo.si('322'), ]), echo.si('32_'), ]),
                ]), echo.si('3_'),
            ]),
        ]),
        echo.si('_'),
        echo.si('#'),
        echo.si('$'),
    ])

    mytasks_explicit_3 = chain([
        echo.si('-> explicit chord (3)'),
        chord([
            chord([
                chord([echo.si('111'), echo.si('112'), ], body=echo.si('11_')),
                chord([echo.si('121'), echo.si('122'), ], body=echo.si('12_')),
            ], body=echo.si('1_')),
            chord([
                chord([echo.si('211'), echo.si('212'), ], body=echo.si('21_')),
                chord([echo.si('221'), echo.si('222'), ], body=echo.si('22_')),
            ], body=echo.si('2_')),
            chord([
                chord([echo.si('311'), echo.si('312'), ], body=echo.si('31_')),
                chord([echo.si('321'), echo.si('322'), ], body=echo.si('32_')),
            ], body=echo.si('3_')),
        ], body=echo.si('_')),
        echo.si('#'),
        echo.si('$'),
    ])

    mytasks_or_operator_3 = echo.si('-> or operator (3)') | group([
        group([
            group([echo.si('111'), echo.si('112'), ]) | echo.si('11_'),
            group([echo.si('121'), echo.si('122'), ]) | echo.si('12_'),
        ]) | echo.si('1_'),
        group([
            group([echo.si('211'), echo.si('212'), ]) | echo.si('21_'),
            group([echo.si('221'), echo.si('222'), ]) | echo.si('22_'),
        ]) | echo.si('2_'),
        group([
            group([echo.si('311'), echo.si('312'), ]) | echo.si('31_'),
            group([echo.si('321'), echo.si('322'), ]) | echo.si('32_'),
        ]) | echo.si('3_'),
    ]) | echo.si('_') | echo.si('#') | echo.si('$')

    # two "tasks" in main chord

    result = mytasks_implicit.apply_async()
    print(result.get())
    time.sleep(1.5)

    result = mytasks_explicit.apply_async()
    print(result.get())
    time.sleep(1.5)

    result = mytasks_or_operator.apply_async()
    print(result.get())
    time.sleep(1.5)

    # three "tasks" in main chord

    result = mytasks_implicit_3.apply_async()
    print(result.get())
    time.sleep(1.5)

    result = mytasks_explicit_3.apply_async()
    print(result.get())
    time.sleep(1.5)

    result = mytasks_or_operator_3.apply_async()
    print(result.get())

celery report

software -> celery:4.0.0rc7 (0today8) kombu:4.0.0 py:2.7.10
billiard:3.5.0.1 py-amqp:2.1.1
platform -> system:Darwin arch:64bit imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:redis://localhost/

task_always_eager: False
broker_url: u'amqp://guest:********@localhost:5672//'
result_backend: u'redis://localhost/'

Expected behavior

All chains should execute the _ # and $ tasks exactly once, in order, at the end of the canvas. I.e. (output when using amqp):

-> implicit chord
111
112
121
122
211
212
221
222
11_
12_
21_
22_
1_
2_
_
#
$
-> explicit chord
111
112
121
122
211
212
221
222
12_
11_
21_
22_
1_
2_
_
#
$
-> or operator
112
111
121
122
211
212
221
222
21_
11_
12_
22_
1_
2_
_
#
$
-> implicit chord (3)
111
112
121
122
211
212
222
221
311
312
321
322
11_
12_
21_
22_
31_
32_
1_
2_
3_
_
#
$
-> explicit chord (3)
111
112
121
122
211
212
221
222
312
311
321
322
11_
12_
21_
22_
31_
32_
1_
2_
3_
_
#
$
-> or operator (3)
111
112
121
122
211
212
221
222
311
312
321
322
11_
12_
21_
22_
31_
32_
1_
2_
3_
_
#
$

Actual behavior

When using redis, the first three canvases execute the last tasks twice; then execution hangs on the fourth canvas (I also tried each canvas individually: the fifth and sixth also hang):

-> implicit chord
111
112
121
122
211
212
221
222
11_
12_
22_
_
21_
#
_
$
#
$
-> explicit chord
111
112
121
122
11_
211
12_
212
221
_
222
21_
#
22_
$
_
#
$
-> or operator
112
111
121
122
11_
12_
211
212
_
221
21_
222
#
22_
$
_
#
$
-> implicit chord (3)
111
112
121
122
11_
211
212
12_
221
222
21_
312
311
321
22_
31_
322
32_

Activity

  1. auvipy commented on Dec 19, 2017

    @auvipy
    Member

    #4437 should fix this, if not plz report

  2. added this to the v4.2 milestone on Dec 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions