<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"> 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"> 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"> 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"> 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"> 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"> 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"> 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>
<ul dir="auto">
<li>None</li>
</ul>
<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>: 4.2.1 (windowlicker)</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="... traceback removed ...
KeyError: 'test'"><pre class="notranslate"><code class="notranslate">... traceback removed ...
KeyError: 'test'
</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=""><pre class="notranslate"><code class="notranslate"></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><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# settings.py
raise KeyError('test')"><pre class="notranslate"><span class="pl-c"># settings.py</span>
<span class="pl-k">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s">'test'</span>)</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Traceback with <code class="notranslate">KeyError: 'test'</code></p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">Actual traceback when running <code class="notranslate">celery -A proj beat -l DEBUG</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py&quot;, line 134, in __getattr__
   return self[k]
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py&quot;, line 442, in __getitem__
   return self.__missing__(key)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py&quot;, line 275, in __missing__
   raise KeyError(key)
KeyError: 'beat_schedule_filename'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File &quot;/usr/local/bin/celery&quot;, line 11, in &lt;module&gt;
   sys.exit(main())
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/__main__.py&quot;, line 16, in main
   _main()
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py&quot;, line 322, in main
   cmd.execute_from_commandline(argv)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py&quot;, line 496, in execute_from_commandline
   super(CeleryCommand, self).execute_from_commandline(argv)))
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/base.py&quot;, line 298, in execute_from_commandline
   return self.handle_argv(self.prog_name, argv[1:])
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py&quot;, line 488, in handle_argv
   return self.execute(command, argv)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py&quot;, line 420, in execute
   ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/base.py&quot;, line 302, in run_from_argv
   sys.argv if argv is None else argv, command)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/base.py&quot;, line 385, in handle_argv
   *self.parse_options(prog_name, argv, command))
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/base.py&quot;, line 421, in parse_options
   self.parser = self.create_parser(prog_name, command)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/base.py&quot;, line 437, in create_parser
   self.add_arguments(parser)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/bin/beat.py&quot;, line 116, in add_arguments
   '-s', '--schedule', default=c.beat_schedule_filename)
 File &quot;/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py&quot;, line 138, in __getattr__
   type(self).__name__, k))
AttributeError: 'Settings' object has no attribute 'beat_schedule_filename'"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
 File "/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py", line 134, in __getattr__
   return self[k]
 File "/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py", line 442, in __getitem__
   return self.__missing__(key)
 File "/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py", line 275, in __missing__
   raise KeyError(key)
KeyError: 'beat_schedule_filename'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "/usr/local/bin/celery", line 11, in &lt;module&gt;
   sys.exit(main())
 File "/usr/local/lib/python3.6/dist-packages/celery/__main__.py", line 16, in main
   _main()
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py", line 322, in main
   cmd.execute_from_commandline(argv)
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py", line 496, in execute_from_commandline
   super(CeleryCommand, self).execute_from_commandline(argv)))
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/base.py", line 298, in execute_from_commandline
   return self.handle_argv(self.prog_name, argv[1:])
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py", line 488, in handle_argv
   return self.execute(command, argv)
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/celery.py", line 420, in execute
   ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/base.py", line 302, in run_from_argv
   sys.argv if argv is None else argv, command)
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/base.py", line 385, in handle_argv
   *self.parse_options(prog_name, argv, command))
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/base.py", line 421, in parse_options
   self.parser = self.create_parser(prog_name, command)
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/base.py", line 437, in create_parser
   self.add_arguments(parser)
 File "/usr/local/lib/python3.6/dist-packages/celery/bin/beat.py", line 116, in add_arguments
   '-s', '--schedule', default=c.beat_schedule_filename)
 File "/usr/local/lib/python3.6/dist-packages/celery/utils/collections.py", line 138, in __getattr__
   type(self).__name__, k))
AttributeError: 'Settings' object has no attribute 'beat_schedule_filename'
</code></pre></div>
<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 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 included all related issues and possible duplicate issues in this issue.</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 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"> I have tried reproducing the issue on more than one message 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 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 retries, ETA/Countdown &amp; rate limits disabled.</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: 4.3.0rc3 (rhubarb)</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:4.3.0rc3 (rhubarb) kombu:4.4.0 py:3.5.3
            billiard:3.6.0.0 py-amqp:2.4.2
platform -&gt; system:Linux arch:64bit
            kernel version:4.9.0-8-amd64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:pyamqp results:rpc:///

broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'rpc:///'
include: ['pyodhean.interface']"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.3.0rc3 (rhubarb) kombu:4.4.0 py:3.5.3
            billiard:3.6.0.0 py-amqp:2.4.2
platform -&gt; system:Linux arch:64bit
            kernel version:4.9.0-8-amd64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:pyamqp results:rpc:///

broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'rpc:///'
include: ['pyodhean.interface']
</code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<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==2.4.2
appdirs==1.4.3
astroid==2.2.5
autopep8==1.4.3
Babel==2.6.0
billiard==3.6.0.0
-e git+ssh://git@github.com/celery/celery@e1f84b06dc812d1a4520f717948328fbae7486be#egg=celery
flake8==3.6.0
flower==0.9.3
isort==4.3.4
kombu==4.4.0
lazy-object-proxy==1.3.1
mccabe==0.6.1
nose==1.3.7
pkg-resources==0.0.0
ply==3.11
pycodestyle==2.4.0
pyflakes==2.0.0
pylint==2.3.1
Pyomo==5.5.1
pytz==2018.9
PyUtilib==5.6.3
six==1.11.0
tornado==5.1.1
typed-ast==1.3.1
vine==1.3.0
wrapt==1.10.11"><pre class="notranslate"><code class="notranslate">amqp==2.4.2
appdirs==1.4.3
astroid==2.2.5
autopep8==1.4.3
Babel==2.6.0
billiard==3.6.0.0
-e git+ssh://git@github.com/celery/celery@e1f84b06dc812d1a4520f717948328fbae7486be#egg=celery
flake8==3.6.0
flower==0.9.3
isort==4.3.4
kombu==4.4.0
lazy-object-proxy==1.3.1
mccabe==0.6.1
nose==1.3.7
pkg-resources==0.0.0
ply==3.11
pycodestyle==2.4.0
pyflakes==2.0.0
pylint==2.3.1
Pyomo==5.5.1
pytz==2018.9
PyUtilib==5.6.3
six==1.11.0
tornado==5.1.1
typed-ast==1.3.1
vine==1.3.0
wrapt==1.10.11
</code></pre></div>
<p dir="auto"></p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import time
from celery import Celery


app = Celery(
    'test',
    backend='rpc://',
    broker='pyamqp://',
)


@app.task
def task():
    return True


task_id = task.delay()
dummy_task_id = '00000000-0000-0000-0000-000000000000'

time.sleep(1)
assert app.AsyncResult(dummy_task_id).state == 'PENDING'
assert app.AsyncResult(task_id).state == 'SUCCESS'
assert app.AsyncResult(task_id).state == 'SUCCESS'  # This fails"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>


<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(
    <span class="pl-s">'test'</span>,
    <span class="pl-s1">backend</span><span class="pl-c1">=</span><span class="pl-s">'rpc://'</span>,
    <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'pyamqp://'</span>,
)


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">task</span>():
    <span class="pl-k">return</span> <span class="pl-c1">True</span>


<span class="pl-s1">task_id</span> <span class="pl-c1">=</span> <span class="pl-s1">task</span>.<span class="pl-en">delay</span>()
<span class="pl-s1">dummy_task_id</span> <span class="pl-c1">=</span> <span class="pl-s">'00000000-0000-0000-0000-000000000000'</span>

<span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)
<span class="pl-k">assert</span> <span class="pl-s1">app</span>.<span class="pl-v">AsyncResult</span>(<span class="pl-s1">dummy_task_id</span>).<span class="pl-s1">state</span> <span class="pl-c1">==</span> <span class="pl-s">'PENDING'</span>
<span class="pl-k">assert</span> <span class="pl-s1">app</span>.<span class="pl-v">AsyncResult</span>(<span class="pl-s1">task_id</span>).<span class="pl-s1">state</span> <span class="pl-c1">==</span> <span class="pl-s">'SUCCESS'</span>
<span class="pl-k">assert</span> <span class="pl-s1">app</span>.<span class="pl-v">AsyncResult</span>(<span class="pl-s1">task_id</span>).<span class="pl-s1">state</span> <span class="pl-c1">==</span> <span class="pl-s">'SUCCESS'</span>  <span class="pl-c"># This fails</span></pre></div>
<h1 dir="auto">Expected Behavior</h1>
<p dir="auto"><code class="notranslate">assert app.AsyncResult(task_id).state</code> should always pass</p>
<h1 dir="auto">Actual Behavior</h1>
<p dir="auto">The second <code class="notranslate">assert app.AsyncResult(task_id).state</code> fails.</p>
<p dir="auto">I believe the issues resides in <a href="https://github.com/celery/celery/blob/master/celery/backends/rpc.py#L236"><code class="notranslate">get_task_meta</code></a>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def get_task_meta(self, task_id, backlog_limit=1000):
        buffered = self._out_of_band.pop(task_id, None)
        if buffered:
            return self._set_cache_by_message(task_id, buffered)

        # Polling and using basic_get
        latest_by_id = {}
        prev = None
        for acc in self._slurp_from_queue(task_id, self.accept, backlog_limit):
            tid = self._get_message_task_id(acc)
            prev, latest_by_id[tid] = latest_by_id.get(tid), acc
            if prev:
                # backends aren't expected to keep history,
                # so we delete everything except the most recent state.
                prev.ack()
                prev = None

        latest = latest_by_id.pop(task_id, None)
        for tid, msg in items(latest_by_id):
            self.on_out_of_band_result(tid, msg)

        if latest:
            latest.requeue()
            return self._set_cache_by_message(task_id, latest)
        else:
            # no new state, use previous
            try:
                return self._cache[task_id]
            except KeyError:
                # result probably pending.
                return {'status': states.PENDING, 'result': None}"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">get_task_meta</span>(<span class="pl-s1">self</span>, <span class="pl-s1">task_id</span>, <span class="pl-s1">backlog_limit</span><span class="pl-c1">=</span><span class="pl-c1">1000</span>):
        <span class="pl-s1">buffered</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_out_of_band</span>.<span class="pl-en">pop</span>(<span class="pl-s1">task_id</span>, <span class="pl-c1">None</span>)
        <span class="pl-k">if</span> <span class="pl-s1">buffered</span>:
            <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_cache_by_message</span>(<span class="pl-s1">task_id</span>, <span class="pl-s1">buffered</span>)

        <span class="pl-c"># Polling and using basic_get</span>
        <span class="pl-s1">latest_by_id</span> <span class="pl-c1">=</span> {}
        <span class="pl-s1">prev</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>
        <span class="pl-k">for</span> <span class="pl-s1">acc</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-en">_slurp_from_queue</span>(<span class="pl-s1">task_id</span>, <span class="pl-s1">self</span>.<span class="pl-s1">accept</span>, <span class="pl-s1">backlog_limit</span>):
            <span class="pl-s1">tid</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_get_message_task_id</span>(<span class="pl-s1">acc</span>)
            <span class="pl-s1">prev</span>, <span class="pl-s1">latest_by_id</span>[<span class="pl-s1">tid</span>] <span class="pl-c1">=</span> <span class="pl-s1">latest_by_id</span>.<span class="pl-en">get</span>(<span class="pl-s1">tid</span>), <span class="pl-s1">acc</span>
            <span class="pl-k">if</span> <span class="pl-s1">prev</span>:
                <span class="pl-c"># backends aren't expected to keep history,</span>
                <span class="pl-c"># so we delete everything except the most recent state.</span>
                <span class="pl-s1">prev</span>.<span class="pl-en">ack</span>()
                <span class="pl-s1">prev</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>

        <span class="pl-s1">latest</span> <span class="pl-c1">=</span> <span class="pl-s1">latest_by_id</span>.<span class="pl-en">pop</span>(<span class="pl-s1">task_id</span>, <span class="pl-c1">None</span>)
        <span class="pl-k">for</span> <span class="pl-s1">tid</span>, <span class="pl-s1">msg</span> <span class="pl-c1">in</span> <span class="pl-en">items</span>(<span class="pl-s1">latest_by_id</span>):
            <span class="pl-s1">self</span>.<span class="pl-en">on_out_of_band_result</span>(<span class="pl-s1">tid</span>, <span class="pl-s1">msg</span>)

        <span class="pl-k">if</span> <span class="pl-s1">latest</span>:
            <span class="pl-s1">latest</span>.<span class="pl-en">requeue</span>()
            <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_cache_by_message</span>(<span class="pl-s1">task_id</span>, <span class="pl-s1">latest</span>)
        <span class="pl-k">else</span>:
            <span class="pl-c"># no new state, use previous</span>
            <span class="pl-k">try</span>:
                <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">_cache</span>[<span class="pl-s1">task_id</span>]
            <span class="pl-k">except</span> <span class="pl-v">KeyError</span>:
                <span class="pl-c"># result probably pending.</span>
                <span class="pl-k">return</span> {<span class="pl-s">'status'</span>: <span class="pl-s1">states</span>.<span class="pl-v">PENDING</span>, <span class="pl-s">'result'</span>: <span class="pl-c1">None</span>}</pre></div>
<p dir="auto">When polling only task_id, the <code class="notranslate">out_of_band</code> buffer is never used, and <code class="notranslate">latest</code> is always requeued.</p>
<p dir="auto">However, when another task is polled, the return message of the task_id task is buffered in <code class="notranslate">out_of_band</code> and never requeued, so it is returned correctly on the next call but then it is lost because it is popped from <code class="notranslate">out_of_band</code>.</p>
<p dir="auto">I get the correct behaviour with any of those two fixes:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def on_out_of_band_result(self, task_id, message):
        if self.result_consumer:
            self.result_consumer.on_out_of_band_result(message)
        self._out_of_band[task_id] = message
        message.requeue()  # &lt;-- requeue"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">on_out_of_band_result</span>(<span class="pl-s1">self</span>, <span class="pl-s1">task_id</span>, <span class="pl-s1">message</span>):
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">result_consumer</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">result_consumer</span>.<span class="pl-en">on_out_of_band_result</span>(<span class="pl-s1">message</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">_out_of_band</span>[<span class="pl-s1">task_id</span>] <span class="pl-c1">=</span> <span class="pl-s1">message</span>
        <span class="pl-s1">message</span>.<span class="pl-en">requeue</span>()  <span class="pl-c"># &lt;-- requeue</span></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def get_task_meta(self, task_id, backlog_limit=1000):
        buffered = self._out_of_band.pop(task_id, None)
        if buffered:
            buffered.requeue()  # &lt;-- requeue
            return self._set_cache_by_message(task_id, buffered)
        [...]"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">get_task_meta</span>(<span class="pl-s1">self</span>, <span class="pl-s1">task_id</span>, <span class="pl-s1">backlog_limit</span><span class="pl-c1">=</span><span class="pl-c1">1000</span>):
        <span class="pl-s1">buffered</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_out_of_band</span>.<span class="pl-en">pop</span>(<span class="pl-s1">task_id</span>, <span class="pl-c1">None</span>)
        <span class="pl-k">if</span> <span class="pl-s1">buffered</span>:
            <span class="pl-s1">buffered</span>.<span class="pl-en">requeue</span>()  <span class="pl-c"># &lt;-- requeue</span>
            <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_cache_by_message</span>(<span class="pl-s1">task_id</span>, <span class="pl-s1">buffered</span>)
        [...]</pre></div>
<p dir="auto">This is as far as I could get. It took me a few hours to figure that out. Hopefully this report provides enough information to be helpful.</p>