Skip to content

Can not work in gevent/eventlet model #6225

Description

@Seumi

Checklist

  • I have verified that the issue exists against the master branch of Celery.
  • This has already been asked to the discussion group first.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the master branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

  • 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).
  • I have verified that the issue exists against the master branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version
    and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or
    result backend.
  • I have tried reproducing the issue on more than one version of the message
    broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • I have tried reproducing the issue with autoscaling, retries,
    ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading
    and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

Possible Duplicates

  • None

Environment & Settings

Celery version: 4.4.6

celery report Output:

software -> celery:4.4.6 (cliffs) kombu:4.6.11 py:3.6.10
            billiard:3.6.3.0 librabbitmq:2.0.0
platform -> system:Linux arch:64bit
            kernel version:4.19.104-microsoft-standard imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:librabbitmq results:redis://:**@127.0.0.1:6379/8

broker_url: 'amqp://myuser:********@127.0.0.1:5672/myvhost'
result_backend: 'redis://:********@127.0.0.1:6379/8'
timezone: 'Asia/Shanghai'

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: 3.6
  • Minimal Celery Version: 4.4.6
  • Minimal Kombu Version: 4.6.11
  • Minimal Broker Version: N/A or Unknown
  • Minimal Result Backend Version: N/A or Unknown
  • Minimal OS and/or Kernel Version: Ubuntu18.04 LTS (WSL2)
  • Minimal Broker Client Version: N/A or Unknown
  • Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

amqp==2.6.0
billiard==3.6.3.0
celery==4.4.6
certifi==2020.6.20
future==0.18.2
gevent==20.6.2
greenlet==0.4.16
importlib-metadata==1.7.0
kombu==4.6.11
librabbitmq==2.0.0
pytz==2020.1
redis==3.5.3
six==1.15.0
vine==1.3.0
zipp==3.1.0
zope.event==4.4
zope.interface==5.1.0

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

from celery import Celery
app = Celery(
    "proj",
    broker='amqp://myuser:[email protected]/myvhost',
    backend="redis://:127.0.0.1:6379/8",
)
@app.task()
def add(x, y):
    return x+y

Just a simple app with 'add' function to return the sum of two number. Run this app by 'celery -A proj -P=gevent -c=10 -l debug'.And than open anonther shell, call the 'add' function by 'res = add.delay(2,2)' and 'res.get()'

Expected Behavior

'res.get()' should return '4' as result

Actual Behavior

'res.get()' seems block forever and never return, it can be seen from the log that the task was indeed accepted'

[2020-07-13 23:56:20,345: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2020-07-13 23:56:20,347: DEBUG/MainProcess] | Worker: Building graph...
[2020-07-13 23:56:20,347: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Pool, Autoscaler, Beat, StateDB, Consumer}
[2020-07-13 23:56:20,365: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2020-07-13 23:56:20,365: DEBUG/MainProcess] | Consumer: Building graph...
[2020-07-13 23:56:20,379: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Gossip, Heart, Tasks, Control, Agent, event loop}

 -------------- celery@SURFACEBOOK-2 v4.4.6 (cliffs)
--- ***** -----
-- ******* ---- Linux-4.19.104-microsoft-standard-x86_64-with-debian-buster-sid 2020-07-13 23:56:20
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app:         Heimdallr:0x7f2e0135d6d8
- ** ---------- .> transport:   amqp://myuser:**@127.0.0.1/myvhost
- ** ---------- .> results:     redis://:**@127.0.0.1:6379/8
- *** --- * --- .> concurrency: 10 (gevent)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[tasks]
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap
  . worker.add

[2020-07-13 23:56:20,400: DEBUG/MainProcess] | Worker: Starting Hub
[2020-07-13 23:56:20,400: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:20,400: DEBUG/MainProcess] | Worker: Starting Pool
[2020-07-13 23:56:20,400: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:20,400: DEBUG/MainProcess] | Worker: Starting Consumer
[2020-07-13 23:56:20,401: DEBUG/MainProcess] | Consumer: Starting Connection
[2020-07-13 23:56:20,702: INFO/MainProcess] Connected to amqp://myuser:**@127.0.0.1:5672/myvhost
[2020-07-13 23:56:20,702: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:20,703: DEBUG/MainProcess] | Consumer: Starting Events
[2020-07-13 23:56:21,024: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:21,025: DEBUG/MainProcess] | Consumer: Starting Mingle
[2020-07-13 23:56:21,025: INFO/MainProcess] mingle: searching for neighbors
[2020-07-13 23:56:23,152: INFO/MainProcess] mingle: sync with 1 nodes
[2020-07-13 23:56:23,153: DEBUG/MainProcess] mingle: processing reply from celery@instance-och4ruob
[2020-07-13 23:56:23,153: INFO/MainProcess] mingle: sync complete
[2020-07-13 23:56:23,153: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:23,154: DEBUG/MainProcess] | Consumer: Starting Gossip
[2020-07-13 23:56:23,549: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:23,549: DEBUG/MainProcess] | Consumer: Starting Heart
[2020-07-13 23:56:23,693: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:23,694: DEBUG/MainProcess] | Consumer: Starting Tasks
[2020-07-13 23:56:23,993: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:23,993: DEBUG/MainProcess] | Consumer: Starting Control
[2020-07-13 23:56:23,994: DEBUG/MainProcess] ^-- substep ok
[2020-07-13 23:56:23,994: DEBUG/MainProcess] | Consumer: Starting event loop
[2020-07-13 23:56:23,994: DEBUG/MainProcess] | Worker: Hub.register Pool...
[2020-07-13 23:56:24,072: INFO/MainProcess] celery@SURFACEBOOK-2 ready.
[2020-07-13 23:56:24,074: DEBUG/MainProcess] basic.qos: prefetch_count->40
[2020-07-13 23:57:14,569: INFO/MainProcess] Received task: worker.add[de4e08e4-336d-465f-ac2e-da55faea1b73]
[2020-07-13 23:57:14,569: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2e012f5268> (args:('worker.add', 'de4e08e4-336d-465f-ac2e-da55faea1b73', {'lang': 'py', 'task': 'worker.add', 'id': 'de4e08e4-336d-465f-ac2e-da55faea1b73', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'de4e08e4-336d-465f-ac2e-da55faea1b73', 'parent_id': None, 'argsrepr': '(2, 2)', 'kwargsrepr': '{}', 'origin': 'gen3136@SURFACEBOOK-2', 'reply_to': '419b4639-2e20-3278-a057-6c4fea63e811', 'correlation_id': 'de4e08e4-336d-465f-ac2e-da55faea1b73', 'hostname': 'celery@SURFACEBOOK-2', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'args': [2, 2], 'kwargs': {}}, <memory at 0x7f2e01eef048>, 'application/json', 'utf-8') kwargs:{})
[2020-07-13 23:57:50,615: INFO/MainProcess] Received task: worker.add[dcba734c-2251-4abc-a1a5-1c31289bd8f1]
[2020-07-13 23:57:50,615: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2e012f5268> (args:('worker.add', 'dcba734c-2251-4abc-a1a5-1c31289bd8f1', {'lang': 'py', 'task': 'worker.add', 'id': 'dcba734c-2251-4abc-a1a5-1c31289bd8f1', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'dcba734c-2251-4abc-a1a5-1c31289bd8f1', 'parent_id': None, 'argsrepr': '(2, 2)', 'kwargsrepr': '{}', 'origin': 'gen8514@SURFACEBOOK-2', 'reply_to': '3bee5d65-442f-3d41-9d9e-25c88986b473', 'correlation_id': 'dcba734c-2251-4abc-a1a5-1c31289bd8f1', 'hostname': 'celery@SURFACEBOOK-2', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': True}, 'args': [2, 2], 'kwargs': {}}, <memory at 0x7f2e01eef108>, 'application/json', 'utf-8') kwargs:{})[2020-07-13 23:57:50,615: INFO/MainProcess] Received task: worker.add[90f858e9-b259-4968-8d59-e546cdc07515]
[2020-07-13 23:57:50,616: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2e012f5268> (args:('worker.add', '90f858e9-b259-4968-8d59-e546cdc07515', {'lang': 'py', 'task': 'worker.add', 'id': '90f858e9-b259-4968-8d59-e546cdc07515', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '90f858e9-b259-4968-8d59-e546cdc07515', 'parent_id': None, 'argsrepr': '(2, 2)', 'kwargsrepr': '{}', 'origin': 'gen8514@SURFACEBOOK-2', 'reply_to': '3bee5d65-442f-3d41-9d9e-25c88986b473', 'correlation_id': '90f858e9-b259-4968-8d59-e546cdc07515', 'hostname': 'celery@SURFACEBOOK-2', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': True}, 'args': [2, 2], 'kwargs': {}}, <memory at 0x7f2e01eef1c8>, 'application/json', 'utf-8') kwargs:{})[2020-07-13 23:57:51,809: INFO/MainProcess] Received task: worker.add[10eb7374-3151-4ca3-b307-2319e1b20878]
[2020-07-13 23:57:51,809: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2e012f5268> (args:('worker.add', '10eb7374-3151-4ca3-b307-2319e1b20878', {'lang': 'py', 'task': 'worker.add', 'id': '10eb7374-3151-4ca3-b307-2319e1b20878', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': '10eb7374-3151-4ca3-b307-2319e1b20878', 'parent_id': None, 'argsrepr': '(2, 2)', 'kwargsrepr': '{}', 'origin': 'gen2895@SURFACEBOOK-2', 'reply_to': '21261e1d-cfc1-3f6b-bfce-cb52049e69a0', 'correlation_id': '10eb7374-3151-4ca3-b307-2319e1b20878', 'hostname': 'celery@SURFACEBOOK-2', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': True}, 'args': [2, 2], 'kwargs': {}}, <memory at 0x7f2e01eef288>, 'application/json', 'utf-8') kwargs:{})[2020-07-13 23:58:13,122: INFO/MainProcess] Received task: worker.add[d3d9fe2d-6cfe-4db9-8b77-dfb83c7f1041]
[2020-07-13 23:58:13,122: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2e012f5268> (args:('worker.add', 'd3d9fe2d-6cfe-4db9-8b77-dfb83c7f1041', {'lang': 'py', 'task': 'worker.add', 'id': 'd3d9fe2d-6cfe-4db9-8b77-dfb83c7f1041', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'd3d9fe2d-6cfe-4db9-8b77-dfb83c7f1041', 'parent_id': None, 'argsrepr': '(2, 2)', 'kwargsrepr': '{}', 'origin': 'gen3136@SURFACEBOOK-2', 'reply_to': '419b4639-2e20-3278-a057-6c4fea63e811', 'correlation_id': 'd3d9fe2d-6cfe-4db9-8b77-dfb83c7f1041', 'hostname': 'celery@SURFACEBOOK-2', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'args': [2, 2], 'kwargs': {}}, <memory at 0x7f2e01eef348>, 'application/json', 'utf-8') kwargs:{})
[2020-07-13 23:58:47,723: DEBUG/MainProcess] celery@instance-och4ruob joined the party
[2020-07-13 23:58:54,904: DEBUG/MainProcess] celery@instance-och4ruob left
^C
worker: Hitting Ctrl+C again will terminate all running tasks!

worker: Warm shutdown (MainProcess)
[2020-07-13 23:59:40,326: DEBUG/MainProcess] | Worker: Closing Hub...
[2020-07-13 23:59:40,326: DEBUG/MainProcess] | Worker: Closing Pool...
[2020-07-13 23:59:40,326: DEBUG/MainProcess] | Worker: Closing Consumer...
[2020-07-13 23:59:40,326: DEBUG/MainProcess] | Worker: Stopping Consumer...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Connection...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Events...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Mingle...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Gossip...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Heart...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Tasks...
[2020-07-13 23:59:40,327: DEBUG/MainProcess] | Consumer: Closing Control...
[2020-07-13 23:59:40,328: DEBUG/MainProcess] | Consumer: Closing event loop...
[2020-07-13 23:59:40,328: DEBUG/MainProcess] | Consumer: Stopping event loop...
[2020-07-13 23:59:40,328: DEBUG/MainProcess] | Consumer: Stopping Control...
[2020-07-13 23:59:40,328: DEBUG/MainProcess] | Consumer: Stopping Tasks...
[2020-07-13 23:59:40,347: DEBUG/MainProcess] Canceling task consumer...
[2020-07-13 23:59:40,425: DEBUG/MainProcess] | Consumer: Stopping Heart...
[2020-07-13 23:59:40,427: DEBUG/MainProcess] | Consumer: Stopping Gossip...
[2020-07-13 23:59:40,594: DEBUG/MainProcess] | Consumer: Stopping Mingle...
[2020-07-13 23:59:40,595: DEBUG/MainProcess] | Consumer: Stopping Events...
[2020-07-13 23:59:40,595: DEBUG/MainProcess] | Consumer: Stopping Connection...
[2020-07-13 23:59:40,595: DEBUG/MainProcess] | Worker: Stopping Pool...
[2020-07-13 23:59:40,906: INFO/MainProcess] pidbox: Connected to amqp://myuser:**@127.0.0.1:5672/myvhost.
[2020-07-13 23:59:49,674: DEBUG/MainProcess] pidbox received method ping() [reply_to:{'exchange': 'reply.celery.pidbox', 'routing_key': '713a54e8-d3d0-3682-926d-ea821da864fd'} ticket:c6616862-2365-48be-9dd2-38368b7cf343]
^C
worker: Cold shutdown (MainProcess)

When use 'celery -A worker inspect ping', it just return 'Error: No nodes replied within time constraint.Error: No nodes replied within time constraint'. If I start multiple different worker(all in gevent model), they can not find each other. But if I start a worker in prefork model, it just works perfectly. Another strange thing is that if press crtl+c, the worker can not warm shutdown completely, 'pidbox: Connected to amqp://myuser:**@127.0.0.1:5672/myvhost.'will appear. If use 'celery -A worker inspect ping' again, it will return a 'pong'.
I have already tried py3.6 and py3.7/redis as broker/rabbitmq as broker/gevent/eventlet/ubutnu18/ubuntu16, the results are basically the same.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions