Issue 1:
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.

Environment & Settings

Celery version:

celery report Output:

software -> celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.9.2
billiard:3.6.4.0 redis:3.5.3
platform -> system:Linux arch:64bit, ELF
kernel version:4.4.0-198-generic imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost/1

broker_url: 'redis://localhost:6379/1'

result_backend: 'redis://localhost/1'

result_serializer: 'pickle'

deprecated_settings: None

task_serializer: 'pickle'

accept_content: ['pickle', 'json']

result_expires: 3600

task_default_queue: 'zabbix'

Steps to Reproduce

Schedule a chord with beat via a task.

I created a task that takes a chain/chord as parameter and executes it, since beat does not allow for scheduling anything but a simple task directly:

@app.task()

def execute_chain(ch):

ch.apply_async(ignore_result=True)

This is added to the beat schedule via

ch = group(*zbxitems) | func.s() | publish_mqtt.s()

sender.add_periodic_task(interval, execute_chain.s(ch), name=name)

Required Dependencies

Python Packages

pip freeze Output:

amqp==5.0.6
billiard==3.6.4.0
celery==5.1.0
certifi==2021.5.30
chardet==4.0.0
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
colorama==0.4.4
idna==2.10
kombu==5.1.0
paho-mqtt==1.5.1
prompt-toolkit==3.0.18
pytz==2021.1
PyYAML==5.4.1
pyzabbix==0.8.2
redis==3.5.3
requests==2.25.1
six==1.16.0
urllib3==1.26.5
vine==5.0.0
wcwidth==0.2.5
(venv) root@vmt

Other Dependencies

version 3.9.5

Expected Behavior

This should continue to work, executing the chain again and again.

Actual Behavior

I works for several hours till it exits with:

2021-06-11 06:25:54,253:CRITICAL:worker.start:line 207:Unrecoverable error: RecursionError('maximum recursion depth exceeded while pickling an object')

Traceback (most recent call last):

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/worker.py", line 203, in start

self.blueprint.start(self)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start

step.start(parent)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 365, in start

return self.obj.start()

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 326, in start

blueprint.start(self)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start

step.start(parent)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 618, in start

c.loop(*c.loop_args())

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/loops.py", line 81, in asynloop

next(loop)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/asynchronous/hub.py", line 361, in create_loop

cb(*cbargs)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 1128, in on_readable

self.cycle.on_readable(fileno)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 398, in on_readable

chan.handlerstype

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 789, in _brpop_read

self.connection._deliver(loads(bytes_to_str(item)), dest)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/transport/virtual/base.py", line 980, in _deliver

callback(message)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/transport/virtual/base.py", line 630, in _callback

return callback(message)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/messaging.py", line 626, in _receive_callback

return on_m(message) if on_m else self.receive(decoded, message)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 586, in on_task_received

strategy(

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/strategy.py", line 201, in task_message_handler

handle(req)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/worker.py", line 221, in _process_task_sem

return self._quick_acquire(self._process_task, req)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/kombu/asynchronous/semaphore.py", line 57, in acquire

callback(*partial_args, **partial_kwargs)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/worker.py", line 226, in _process_task

req.execute_using_pool(self.pool)

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/worker/request.py", line 691, in execute_using_pool

result = apply_async(

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/concurrency/base.py", line 152, in apply_async

return self.on_apply(target, args, kwargs,

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/billiard/pool.py", line 1530, in apply_async

self._quick_put((TASK, (result._job, None, func, args, kwds)))

File "/usr/share/nd_zabbixexport/venv/lib/python3.9/site-packages/celery/concurrency/asynpool.py", line 859, in send_job

body = dumps(tup, protocol=protocol)

RecursionError: maximum recursion depth exceeded while pickling an object

When json dumping the task, I see this after a few iterations (mind the kwargs):

2021-06-11 16:44:16,370:DEBUG:beat.execute_chain:line 90:{"task": "celery.chord", "args": [], "kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {

"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {"kwargs": {}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}, "header": [{"task": "tasks.zabbix.get

_zabbix_items_value", "args": ["Memory Free", "rd servers"], "kwargs": {}, "options": {}, "subtask_type": null, "immutable": true}, {"task": "tasks.zabbix.get_zabbix_items_value", "args": ["Available memory", "rd servers"], "kwargs": {}, "options": {}, "subtask_type": n

ull, "immutable": true}], "body": {"task": "celery.chain", "args": [], "kwargs": {"tasks": [{"task": "tasks.aggregate.percentage_per_item", "args": [], "kwargs": {}, "options": {}, "subtask_type": null, "immutable": false}, {"task": "tasks.mqtt.publish_mqtt", "args": ["

vmmqtt01", "zabbix/"], "kwargs": {}, "options": {}, "subtask_type": null, "immutable": false}]}, "options": {}, "subtask_type": "chain", "immutable": false}}, "options": {}, "subtask_type": "chord", "immutable": false}

I tried also by cloning the chord first in the scheduled task and executing the clone, but same result.

Issue 2:
AsyncResult memory leak on task producers when producers retrieves task results from redis results backend. We are using redis as broker and results backend.

This is issue is similar to #4839. I have attempted to backport this fix: #5332 with vine 1.3 + celery 4.2.2. However, leak of AsyncResult objects continues to happen for task that retrieves the results from redis backend. Tasks that ignores the results do not exhibit this leak when changes are backported from #5332. Only patch that worked for me was removing del method completely: https://github.com/celery/celery/blame/v4.2.2/celery/result.py#L382

Celery version: 4.2.2

Kombu: 4.2.2

Vine: 1.3.0

Python: 2.7

I have attempted to reproduce the issue with celery 4.1.1 but it works on that version.

Checklist

I have verified that the issue exists against the master branch of Celery.

This has already been asked to the discussion group first.

[x ] I have read the relevant section in the

contribution guide

on reporting bugs.

[ x] I have checked the issues list

for similar or identical bug reports.

[x ] 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.

[ x] I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

[x ] 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.

[ x] I have included the contents of pip freeze in the issue.

[x ] 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.

[x ] I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.