Issue 1:
Checklist

I have checked the issues list

for similar or identical feature requests.

I have checked the pull requests list

for existing proposed implementations of this feature.

I have checked the commit log

to find out if the if the same feature was already implemented 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).

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Brief Summary

Design

Architectural Considerations

How to link a task to an other running task

like this?

result = celery.AsyncResult(parents_task.task_id)
result.add_children(new_task_id)

Proposed Behavior

Proposed UI/UX

Diagrams

N/A

Alternatives

None

Issue 2:
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

- #4465

Possible Duplicates

None

Environment & Settings

Celery version:

celery report Output:

software -> celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.8.8
billiard:3.6.4.0 redis:3.5.3
platform -> system:Darwin arch:64bit
kernel version:20.4.0 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis:///

broker_url: 'redis://localhost:6379//'
result_backend: 'redis:///'
task_queue_max_priority: 10
deprecated_settings: None

Steps to Reproduce

Required Dependencies

Minimal Python Version: N/A or Unknown

Minimal Celery Version: N/A or Unknown

Minimal Kombu Version: N/A or Unknown

Minimal Broker Version: N/A or Unknown

Minimal Result Backend Version: N/A or Unknown

Minimal OS and/or Kernel Version: N/A or Unknown

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

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
dnspython==1.16.0
eventlet==0.31.0
Flask==2.0.1
greenlet==1.1.0
idna==2.10
itsdangerous==2.0.1
Jinja2==3.0.1
kombu==5.1.0
MarkupSafe==2.0.1
prompt-toolkit==3.0.18
pytz==2021.1
redis==3.5.3
requests==2.25.1
six==1.16.0
urllib3==1.26.5
vine==5.0.0
wcwidth==0.2.5
Werkzeug==2.0.1

Other Dependencies

N/A

Minimally Reproducible Test Case

tasks.py

import time
from celery import Celery

app = Celery('tasks', backend='redis://', broker='redis://', task_queue_max_priority=10)

@app.task
def sleep():
time.sleep(1)

web.py

from flask import Flask
from tasks import sleep
app = Flask(__name__)

@app.route('/')
def hello_world():
result = sleep.apply_async()
result.wait()
return '', 200

if __name__ == '__main__':
app.run(port=4444)

simulate.py

import requests
for i in range(20):
requests.get("http://localhost:4444")

pip install celery[redis] requests flask

Start redis

docker run -p 6379:6379 --name redis redis

Run celery celery -A tasks worker --loglevel=INFO

Run web server python web.py

connect to redis

docker exec -it redis /bin/bash
redis-cli
info Clients

Note the connected_clients number

simulate requests python simulate.py

Run info Clients again in redis-cli.

Note the connected_clients number which is now a lot higher

Expected Behavior

Connections close after getting/waiting for a result

Actual Behavior

I'm experiencing a very strange problem with redis connections staying open after each request (after each result.wait() or result.get()).

Help will be super appreciated.

Running flask with threaded=False solves the issue.

Obviously this is a simplified reproduction code. Our real environment is gunicorn, eventlet, flask, redis, celery.

In production we are getting 60k open connections to redis quite fast and we had to restart our server a few times to reset the leaks.