<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?utf8=%E2%9C%93&amp;q=is%3Aissue+label%3A%22Issue+Type%3A+Feature+Request%22+">issues list</a><br>
for similar or identical feature requests.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?utf8=%E2%9C%93&amp;q=is%3Apr+label%3A%22PR+Type%3A+Feature%22+">pull requests list</a><br>
for existing proposed implementations of this feature.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the if the same feature was already implemented in the<br>
master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h1 dir="auto">Brief Summary</h1>

<h1 dir="auto">Design</h1>
<h2 dir="auto">Architectural Considerations</h2>

<p dir="auto">How to link a task to an other running task</p>
<p dir="auto">like this?</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="result = celery.AsyncResult(parents_task.task_id)
result.add_children(new_task_id)"><pre class="notranslate"><span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">celery</span>.<span class="pl-v">AsyncResult</span>(<span class="pl-s1">parents_task</span>.<span class="pl-s1">task_id</span>)
<span class="pl-s1">result</span>.<span class="pl-en">add_children</span>(<span class="pl-s1">new_task_id</span>)</pre></div>
<h2 dir="auto">Proposed Behavior</h2>

<h2 dir="auto">Proposed UI/UX</h2>

<h2 dir="auto">Diagrams</h2>

<p dir="auto">N/A</p>
<h2 dir="auto">Alternatives</h2>

<p dir="auto">None</p>
<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> This has already been asked to the <a href="https://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<h2 dir="auto">- <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="284694904" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/4465" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/4465/hovercard" href="https://github.com/celery/celery/issues/4465">#4465</a></h2>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.8.8
            billiard:3.6.4.0 redis:3.5.3
platform -&gt; system:Darwin arch:64bit
            kernel version:20.4.0 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis:///

broker_url: 'redis://localhost:6379//'
result_backend: 'redis:///'
task_queue_max_priority: 10
deprecated_settings: None"><pre class="notranslate"><code class="notranslate">software -&gt; celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.8.8
            billiard:3.6.4.0 redis:3.5.3
platform -&gt; system:Darwin arch:64bit
            kernel version:20.4.0 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis:///

broker_url: 'redis://localhost:6379//'
result_backend: 'redis:///'
task_queue_max_priority: 10
deprecated_settings: None
</code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Celery Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><p dir="auto">tasks.py</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)"><pre class="notranslate"><code class="notranslate">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)
</code></pre></div>
<p dir="auto">web.py</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)"><pre class="notranslate"><code class="notranslate">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)
</code></pre></div>
<p dir="auto">simulate.py</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import requests
for i in range(20):
    requests.get(&quot;http://localhost:4444&quot;)"><pre class="notranslate"><code class="notranslate">import requests
for i in range(20):
    requests.get("http://localhost:4444")
</code></pre></div>
<ol dir="auto">
<li><code class="notranslate">pip install celery[redis] requests flask</code></li>
<li>Start redis<br>
<code class="notranslate">docker run -p 6379:6379 --name redis redis</code></li>
<li>Run celery <code class="notranslate">celery -A tasks worker --loglevel=INFO</code></li>
<li>Run web server <code class="notranslate">python web.py</code></li>
<li>connect to redis</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="docker exec -it redis /bin/bash
redis-cli
info Clients"><pre class="notranslate"><code class="notranslate">docker exec -it redis /bin/bash
redis-cli
info Clients
</code></pre></div>
<p dir="auto">Note the <code class="notranslate">connected_clients</code> number</p>
<ol dir="auto">
<li>simulate requests <code class="notranslate">python simulate.py</code></li>
<li>Run <code class="notranslate">info Clients</code> again in redis-cli.<br>
Note the <code class="notranslate">connected_clients</code> number which is now a lot higher</li>
</ol>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Connections close after getting/waiting for a result</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">I'm experiencing a very strange problem with redis connections staying open after each request (after each result.wait() or result.get()).</p>
<p dir="auto">Help will be super appreciated.<br>
Running flask with <code class="notranslate">threaded=False</code> solves the issue.<br>
Obviously this is a simplified reproduction code. Our real environment is gunicorn, eventlet, flask, redis, celery.<br>
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.</p>