<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"> 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" checked=""> 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>
<p dir="auto">Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="631048686" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/6158" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/6158/hovercard" href="https://github.com/celery/celery/issues/6158">#6158</a> is about REVOKED states not always being reflected, but I believe this issue is more specific (e.g. the state should not be RETRY).</p>
<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>:  5.1.0 (sun-harmonics)</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="$ celery -A celery_revoke_retry report

software -&gt; celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.7.9
            billiard:3.6.4.0 redis:3.5.0
platform -&gt; system:Linux arch:64bit, ELF
            kernel version:3.10.0-1160.11.1.el7.x86_64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://localhost:6379/0

broker_url: 'redis://localhost:6379/0'
result_backend: 'redis://localhost:6379/0'
deprecated_settings: None
worker_concurrency: 1"><pre class="notranslate"><code class="notranslate">$ celery -A celery_revoke_retry report

software -&gt; celery:5.1.0 (sun-harmonics) kombu:5.1.0 py:3.7.9
            billiard:3.6.4.0 redis:3.5.0
platform -&gt; system:Linux arch:64bit, ELF
            kernel version:3.10.0-1160.11.1.el7.x86_64 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://localhost:6379/0

broker_url: 'redis://localhost:6379/0'
result_backend: 'redis://localhost:6379/0'
deprecated_settings: None
worker_concurrency: 1
</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="
import threading
import time
from celery import Celery

app = Celery('celery_revoke_retry', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
app.conf.update(worker_concurrency=1)

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

def main():
    argv = ['--app=celery_revoke_retry', 'worker', '--loglevel=DEBUG']
    threading.Thread(target=app.worker_main, args=(argv,)).start()
    time.sleep(5)
    print('Celery should be up now')

    r = sleep.s(sleep_time=60).apply_async()
    # Note: waiting for the task to start before revoking it will still cause result.state == RETRY
    r.revoke(terminate=True)

    for _ in range(5):
        print(f&quot;State is: {r.state}&quot;)
        time.sleep(1)

if __name__ == '__main__':
    main()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">threading</span>
<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">'celery_revoke_retry'</span>, <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'redis://localhost:6379/0'</span>, <span class="pl-s1">backend</span><span class="pl-c1">=</span><span class="pl-s">'redis://localhost:6379/0'</span>)
<span class="pl-s1">app</span>.<span class="pl-s1">conf</span>.<span class="pl-en">update</span>(<span class="pl-s1">worker_concurrency</span><span class="pl-c1">=</span><span class="pl-c1">1</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">sleep</span>(<span class="pl-s1">sleep_time</span>):
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-s1">sleep_time</span>)

<span class="pl-k">def</span> <span class="pl-en">main</span>():
    <span class="pl-s1">argv</span> <span class="pl-c1">=</span> [<span class="pl-s">'--app=celery_revoke_retry'</span>, <span class="pl-s">'worker'</span>, <span class="pl-s">'--loglevel=DEBUG'</span>]
    <span class="pl-s1">threading</span>.<span class="pl-v">Thread</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">app</span>.<span class="pl-s1">worker_main</span>, <span class="pl-s1">args</span><span class="pl-c1">=</span>(<span class="pl-s1">argv</span>,)).<span class="pl-en">start</span>()
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">5</span>)
    <span class="pl-en">print</span>(<span class="pl-s">'Celery should be up now'</span>)

    <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">sleep</span>.<span class="pl-en">s</span>(<span class="pl-s1">sleep_time</span><span class="pl-c1">=</span><span class="pl-c1">60</span>).<span class="pl-en">apply_async</span>()
    <span class="pl-c"># Note: waiting for the task to start before revoking it will still cause result.state == RETRY</span>
    <span class="pl-s1">r</span>.<span class="pl-en">revoke</span>(<span class="pl-s1">terminate</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

    <span class="pl-k">for</span> <span class="pl-s1">_</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">5</span>):
        <span class="pl-en">print</span>(<span class="pl-s">f"State is: <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">r</span>.<span class="pl-s1">state</span><span class="pl-kos">}</span></span>"</span>)
        <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-en">main</span>()</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>
<p dir="auto">After revoking the task, the expectation is that the state will not be RETRY. The state should be REVOKED, but my understanding is that there are other known issues that cause an un-received task to not have state=REVOKED after it is revoked.</p>
<p dir="auto">Note that even if the code sample above waiting for the task to be started before executing the revoke, the state will still become RETRY.</p>
<p dir="auto">This appears to be a Celery 5.x regression. The previous 4.x version I was on did not exhibit this behaviour.</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">The code above will print the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="State is: PENDING
Terminating 289825dd-4c07-4018-907a-9f9763e941fe (Signals.SIGTERM)
State is: RETRY
State is: RETRY
State is: RETRY
State is: RETRY"><pre class="notranslate"><code class="notranslate">State is: PENDING
Terminating 289825dd-4c07-4018-907a-9f9763e941fe (Signals.SIGTERM)
State is: RETRY
State is: RETRY
State is: RETRY
State is: RETRY
</code></pre></div>
<p dir="auto">Note that the state should be REVOKED, not RETRY. I believe the previous behaviour was that a task that was never received would stay PENDING if it is revoked.</p>
<p dir="auto">My configuration is as follows (running as administrator)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.0.0 (latentcall) kombu:4.0.0 py:3.5.2
            billiard:3.5.0.2 py-amqp:2.1.1
platform -&gt; system:Windows arch:32bit, WindowsPE imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:disabled

broker_url: 'amqp://guest:********@localhost:5672//'"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.0.0 (latentcall) kombu:4.0.0 py:3.5.2
            billiard:3.5.0.2 py-amqp:2.1.1
platform -&gt; system:Windows arch:32bit, WindowsPE imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:disabled

broker_url: 'amqp://guest:********@localhost:5672//'
</code></pre></div>
<h2 dir="auto">Steps to reproduce (tasks.py)</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from celery import Celery

app = Celery('tasks', broker='amqp://guest:guest@localhost:5672//')

@app.task(ignore_result=True, serializer='json')
def print_hello():
    print('hello there')

@app.task(serializer='json')
def gen_prime(x):
    multiples = []
    results = []
    for i in xrange(2, x+1):
        if i not in multiples:
            results.append(i)
            for j in xrange(i*i, x+1, i):
                multiples.append(j)
    return results"><pre class="notranslate"><code class="notranslate">from celery import Celery

app = Celery('tasks', broker='amqp://guest:guest@localhost:5672//')

@app.task(ignore_result=True, serializer='json')
def print_hello():
    print('hello there')

@app.task(serializer='json')
def gen_prime(x):
    multiples = []
    results = []
    for i in xrange(2, x+1):
        if i not in multiples:
            results.append(i)
            for j in xrange(i*i, x+1, i):
                multiples.append(j)
    return results
</code></pre></div>
<blockquote>
<p dir="auto">celery worker -A tasks</p>
</blockquote>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">Worker running successfully</p>
<h2 dir="auto">Actual behavior</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" -------------- celery@CMENGU-PC v4.0.0 (latentcall)
---- **** -----
--- * ***  * -- Windows-7-6.1.7601-SP1 2016-11-07 23:25:16
-- * - **** ---
- ** ---------- [config]
- ** ---------- .&gt; app:         tasks:0x34f0790
- ** ---------- .&gt; transport:   amqp://guest:**@localhost:5672//
- ** ---------- .&gt; results:     disabled://
- *** --- * --- .&gt; concurrency: 8 (prefork)
-- ******* ---- .&gt; task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
 -------------- [queues]
                .&gt; celery           exchange=celery(direct) key=celery


[2016-11-07 23:25:16,511: CRITICAL/MainProcess] Unrecoverable error: AttributeError(&quot;Can't pickle loca
l object 'Pool.__init__.&lt;locals&gt;.Process'&quot;,)
Traceback (most recent call last):
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\worker\work
er.py&quot;, line 203, in start
    self.blueprint.start(self)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\bootsteps.p
y&quot;, line 119, in start
    step.start(parent)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\bootsteps.p
y&quot;, line 370, in start
    return self.obj.start()
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\concurrency
\base.py&quot;, line 131, in start
    self.on_start()
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\concurrency
\prefork.py&quot;, line 112, in on_start
    **self.options)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\pool.py&quot;,
 line 1008, in __init__
    self._create_worker_process(i)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\pool.py&quot;,
 line 1117, in _create_worker_process
    w.start()
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\process.p
y&quot;, line 122, in start
    self._popen = self._Popen(self)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\context.p
y&quot;, line 383, in _Popen
    return Popen(process_obj)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\popen_spa
wn_win32.py&quot;, line 79, in __init__
    reduction.dump(process_obj, to_child)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\reduction
.py&quot;, line 99, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Pool.__init__.&lt;locals&gt;.Process'

C:\Users\CMENGU\Desktop\celery-app\messaging&gt;Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\spawn.py&quot;
, line 159, in spawn_main
    new_handle = steal_handle(parent_pid, pipe_handle)
  File &quot;c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\reduction
.py&quot;, line 126, in steal_handle
    _winapi.DUPLICATE_SAME_ACCESS | _winapi.DUPLICATE_CLOSE_SOURCE)
PermissionError: [WinError 5] Access is denied"><pre class="notranslate"><code class="notranslate"> -------------- celery@CMENGU-PC v4.0.0 (latentcall)
---- **** -----
--- * ***  * -- Windows-7-6.1.7601-SP1 2016-11-07 23:25:16
-- * - **** ---
- ** ---------- [config]
- ** ---------- .&gt; app:         tasks:0x34f0790
- ** ---------- .&gt; transport:   amqp://guest:**@localhost:5672//
- ** ---------- .&gt; results:     disabled://
- *** --- * --- .&gt; concurrency: 8 (prefork)
-- ******* ---- .&gt; task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
 -------------- [queues]
                .&gt; celery           exchange=celery(direct) key=celery


[2016-11-07 23:25:16,511: CRITICAL/MainProcess] Unrecoverable error: AttributeError("Can't pickle loca
l object 'Pool.__init__.&lt;locals&gt;.Process'",)
Traceback (most recent call last):
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\worker\work
er.py", line 203, in start
    self.blueprint.start(self)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\bootsteps.p
y", line 119, in start
    step.start(parent)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\bootsteps.p
y", line 370, in start
    return self.obj.start()
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\concurrency
\base.py", line 131, in start
    self.on_start()
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\celery\concurrency
\prefork.py", line 112, in on_start
    **self.options)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\pool.py",
 line 1008, in __init__
    self._create_worker_process(i)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\pool.py",
 line 1117, in _create_worker_process
    w.start()
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\process.p
y", line 122, in start
    self._popen = self._Popen(self)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\context.p
y", line 383, in _Popen
    return Popen(process_obj)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\popen_spa
wn_win32.py", line 79, in __init__
    reduction.dump(process_obj, to_child)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\reduction
.py", line 99, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Pool.__init__.&lt;locals&gt;.Process'

C:\Users\CMENGU\Desktop\celery-app\messaging&gt;Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\spawn.py"
, line 159, in spawn_main
    new_handle = steal_handle(parent_pid, pipe_handle)
  File "c:\users\cmengu\appdata\local\programs\python\python35-32\lib\site-packages\billiard\reduction
.py", line 126, in steal_handle
    _winapi.DUPLICATE_SAME_ACCESS | _winapi.DUPLICATE_CLOSE_SOURCE)
PermissionError: [WinError 5] Access is denied
</code></pre></div>
<p dir="auto">It says a permission error but I am running on admin privileges. Not really sure whats going on.</p>