<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.<br>
-- <a href="https://groups.google.com/g/celery-users/c/uqCUtMUu8XY" rel="nofollow">https://groups.google.com/g/celery-users/c/uqCUtMUu8XY</a></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" checked=""> 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" checked=""> 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" checked=""> 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" checked=""> 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" checked=""> 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>
<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>: 5.0.5 (singularity)</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.0.5 (singularity) kombu:5.0.2 py:3.7.6
            billiard:3.6.3.0 redis:3.5.3
platform -&gt; system:Darwin arch:64bit
            kernel version:17.7.0 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://lo"><pre class="notranslate"><code class="notranslate">software -&gt; celery:5.0.5 (singularity) kombu:5.0.2 py:3.7.6
            billiard:3.6.3.0 redis:3.5.3
platform -&gt; system:Darwin arch:64bit
            kernel version:17.7.0 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://lo
</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>: 5.0.0</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.2
billiard==3.6.3.0
celery @ git+https://github.com/celery/celery.git@491054f2724141cbff20731753379459af033bfd
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
importlib-metadata==3.3.0
kombu==5.0.2
prompt-toolkit==3.0.8
pytz==2020.4
redis==3.5.3
six==1.15.0
typing-extensions==3.7.4.3
vine==5.0.0
wcwidth==0.2.5
zipp==3.4.0"><pre class="notranslate"><code class="notranslate">amqp==5.0.2
billiard==3.6.3.0
celery @ git+https://github.com/celery/celery.git@491054f2724141cbff20731753379459af033bfd
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
importlib-metadata==3.3.0
kombu==5.0.2
prompt-toolkit==3.0.8
pytz==2020.4
redis==3.5.3
six==1.15.0
typing-extensions==3.7.4.3
vine==5.0.0
wcwidth==0.2.5
zipp==3.4.0
</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">app.py</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from celery import Celery

app = Celery(broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')

@app.task(bind=True)
def worker_name(self):
    return self.request.hostname"><pre class="notranslate"><code class="notranslate">from celery import Celery

app = Celery(broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')

@app.task(bind=True)
def worker_name(self):
    return self.request.hostname
</code></pre></div>
<p dir="auto">main.py</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from app import worker_name

res = worker_name.delay()
print(res.get())"><pre class="notranslate"><code class="notranslate">from app import worker_name

res = worker_name.delay()
print(res.get())
</code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">As described in the documentation <code class="notranslate">task.request.hostname</code> should be the node name of the worker instance executing the task. See <a href="https://docs.celeryproject.org/en/latest/userguide/tasks.html#task-request-info" rel="nofollow">https://docs.celeryproject.org/en/latest/userguide/tasks.html#task-request-info</a></p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto"><code class="notranslate">task.request.hostname</code> no longer contains the node name of the worker. Only the hostname of the worker. For example if the worker is started with <code class="notranslate">-n whoopsie@%h</code> only the <code class="notranslate">%h</code> bit is included in <code class="notranslate">task.request.hostname</code>. In fact if the worker is started <code class="notranslate">-n whoopsie@computer</code> it will still only report the hostname of the worker machine and not what has been put into the node name.</p>
<p dir="auto">This issue appeared between v4.4.7 and v5.0.0 and is present in current master. It is really useful for debugging purposes to know what exact worker instance a task is executed in if there are multiple workers on the same host.</p>
<p dir="auto">It appears that the worker is at least aware of its worker name based on the worker logs:</p>
<details>
<summary><b><code class="notranslate">celery -A app.app  worker -n whoopsie@computer --loglevel=DEBUG</code></b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2020-12-22 10:40:06,971: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2020-12-22 10:40:06,973: DEBUG/MainProcess] | Worker: Building graph...
[2020-12-22 10:40:06,974: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Pool, Autoscaler, StateDB, Beat, Consumer}
[2020-12-22 10:40:06,986: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2020-12-22 10:40:06,987: DEBUG/MainProcess] | Consumer: Building graph...
[2020-12-22 10:40:07,014: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Heart, Mingle, Tasks, Control, Agent, Gossip, event loop}
 
 -------------- whoopsie@computer v5.0.5 (singularity)
--- ***** ----- 
-- ******* ---- Darwin-17.7.0-x86_64-i386-64bit 2020-12-22 10:40:07
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .&gt; app:         __main__:0x10f0db990
- ** ---------- .&gt; transport:   redis://localhost:6379/0
- ** ---------- .&gt; results:     redis://localhost:6379/0
- *** --- * --- .&gt; concurrency: 4 (prefork)
-- ******* ---- .&gt; task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .&gt; celery           exchange=celery(direct) key=celery
                

[tasks]
  . app.worker_name
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap

[2020-12-22 10:40:07,041: DEBUG/MainProcess] | Worker: Starting Hub
[2020-12-22 10:40:07,041: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,042: DEBUG/MainProcess] | Worker: Starting Pool
[2020-12-22 10:40:07,237: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,238: DEBUG/MainProcess] | Worker: Starting Consumer
[2020-12-22 10:40:07,239: DEBUG/MainProcess] | Consumer: Starting Connection
[2020-12-22 10:40:07,286: INFO/MainProcess] Connected to redis://localhost:6379/0
[2020-12-22 10:40:07,287: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,287: DEBUG/MainProcess] | Consumer: Starting Events
[2020-12-22 10:40:07,310: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,311: DEBUG/MainProcess] | Consumer: Starting Heart
[2020-12-22 10:40:07,317: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,317: DEBUG/MainProcess] | Consumer: Starting Mingle
[2020-12-22 10:40:07,317: INFO/MainProcess] mingle: searching for neighbors
[2020-12-22 10:40:08,397: INFO/MainProcess] mingle: all alone
[2020-12-22 10:40:08,397: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,397: DEBUG/MainProcess] | Consumer: Starting Tasks
[2020-12-22 10:40:08,405: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,405: DEBUG/MainProcess] | Consumer: Starting Control
[2020-12-22 10:40:08,422: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,423: DEBUG/MainProcess] | Consumer: Starting Gossip
[2020-12-22 10:40:08,446: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,446: DEBUG/MainProcess] | Consumer: Starting event loop
[2020-12-22 10:40:08,446: DEBUG/MainProcess] | Worker: Hub.register Pool...
[2020-12-22 10:40:08,447: INFO/MainProcess] whoopsie@computer ready.
[2020-12-22 10:40:08,448: DEBUG/MainProcess] basic.qos: prefetch_count-&gt;16
[2020-12-22 10:40:16,492: INFO/MainProcess] Received task: app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901]  
[2020-12-22 10:40:16,493: DEBUG/MainProcess] TaskPool: Apply &lt;function _trace_task_ret at 0x10f05b3b0&gt; (args:('app.worker_name', 'd5f96484-0a00-4726-ac54-222765aa0901', {'lang': 'py', 'task': 'app.worker_name', 'id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'group_index': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': 'gen3304@Fredriks-MacBook-Pro.local', 'reply_to': 'a0afc794-880a-3e05-970f-5013e0b0ed61', 'correlation_id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'hostname': 'whoopsie@computer', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}, 'args': [], 'kwargs': {}}, b'[[], {}, {&quot;callbacks&quot;: null, &quot;errbacks&quot;: null, &quot;chain&quot;: null, &quot;chord&quot;: null}]', 'application/json', 'utf-8') kwargs:{})
[2020-12-22 10:40:16,495: DEBUG/MainProcess] Task accepted: app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901] pid:3300
[2020-12-22 10:40:16,513: INFO/ForkPoolWorker-2] Task app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901] succeeded in 0.016767310000000535s: 'Fredriks-MacBook-Pro.local'"><pre class="notranslate"><code class="notranslate">[2020-12-22 10:40:06,971: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2020-12-22 10:40:06,973: DEBUG/MainProcess] | Worker: Building graph...
[2020-12-22 10:40:06,974: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Pool, Autoscaler, StateDB, Beat, Consumer}
[2020-12-22 10:40:06,986: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2020-12-22 10:40:06,987: DEBUG/MainProcess] | Consumer: Building graph...
[2020-12-22 10:40:07,014: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Heart, Mingle, Tasks, Control, Agent, Gossip, event loop}
 
 -------------- whoopsie@computer v5.0.5 (singularity)
--- ***** ----- 
-- ******* ---- Darwin-17.7.0-x86_64-i386-64bit 2020-12-22 10:40:07
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .&gt; app:         __main__:0x10f0db990
- ** ---------- .&gt; transport:   redis://localhost:6379/0
- ** ---------- .&gt; results:     redis://localhost:6379/0
- *** --- * --- .&gt; concurrency: 4 (prefork)
-- ******* ---- .&gt; task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .&gt; celery           exchange=celery(direct) key=celery
                

[tasks]
  . app.worker_name
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap

[2020-12-22 10:40:07,041: DEBUG/MainProcess] | Worker: Starting Hub
[2020-12-22 10:40:07,041: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,042: DEBUG/MainProcess] | Worker: Starting Pool
[2020-12-22 10:40:07,237: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,238: DEBUG/MainProcess] | Worker: Starting Consumer
[2020-12-22 10:40:07,239: DEBUG/MainProcess] | Consumer: Starting Connection
[2020-12-22 10:40:07,286: INFO/MainProcess] Connected to redis://localhost:6379/0
[2020-12-22 10:40:07,287: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,287: DEBUG/MainProcess] | Consumer: Starting Events
[2020-12-22 10:40:07,310: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,311: DEBUG/MainProcess] | Consumer: Starting Heart
[2020-12-22 10:40:07,317: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:07,317: DEBUG/MainProcess] | Consumer: Starting Mingle
[2020-12-22 10:40:07,317: INFO/MainProcess] mingle: searching for neighbors
[2020-12-22 10:40:08,397: INFO/MainProcess] mingle: all alone
[2020-12-22 10:40:08,397: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,397: DEBUG/MainProcess] | Consumer: Starting Tasks
[2020-12-22 10:40:08,405: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,405: DEBUG/MainProcess] | Consumer: Starting Control
[2020-12-22 10:40:08,422: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,423: DEBUG/MainProcess] | Consumer: Starting Gossip
[2020-12-22 10:40:08,446: DEBUG/MainProcess] ^-- substep ok
[2020-12-22 10:40:08,446: DEBUG/MainProcess] | Consumer: Starting event loop
[2020-12-22 10:40:08,446: DEBUG/MainProcess] | Worker: Hub.register Pool...
[2020-12-22 10:40:08,447: INFO/MainProcess] whoopsie@computer ready.
[2020-12-22 10:40:08,448: DEBUG/MainProcess] basic.qos: prefetch_count-&gt;16
[2020-12-22 10:40:16,492: INFO/MainProcess] Received task: app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901]  
[2020-12-22 10:40:16,493: DEBUG/MainProcess] TaskPool: Apply &lt;function _trace_task_ret at 0x10f05b3b0&gt; (args:('app.worker_name', 'd5f96484-0a00-4726-ac54-222765aa0901', {'lang': 'py', 'task': 'app.worker_name', 'id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'group_index': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': 'gen3304@Fredriks-MacBook-Pro.local', 'reply_to': 'a0afc794-880a-3e05-970f-5013e0b0ed61', 'correlation_id': 'd5f96484-0a00-4726-ac54-222765aa0901', 'hostname': 'whoopsie@computer', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}, 'args': [], 'kwargs': {}}, b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8') kwargs:{})
[2020-12-22 10:40:16,495: DEBUG/MainProcess] Task accepted: app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901] pid:3300
[2020-12-22 10:40:16,513: INFO/ForkPoolWorker-2] Task app.worker_name[d5f96484-0a00-4726-ac54-222765aa0901] succeeded in 0.016767310000000535s: 'Fredriks-MacBook-Pro.local'
</code></pre></div>
<p dir="auto"></p>
</details>
<p dir="auto">If for some reason the private key used as <code class="notranslate">broker_use_ssl.keyfile</code> is not an RSA private key,  Celery will crash without  telling the root cause, leading to difficult debugging. This affects current celery master branch.</p>
<p dir="auto">This is due to celery.security.key.PrivateKey <code class="notranslate">__init__</code> method not checking the returned key type from <code class="notranslate">load_pem_private_key</code> (from <code class="notranslate">cryptography.hazmat</code>). If the returned key is, for example, <a href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" rel="nofollow">EllipticCurvePrivateKey</a>, the <code class="notranslate">sign</code> method of PrivateKey later will crash with <code class="notranslate">TypeError: sign() takes 3 positional arguments but 4 were given</code> as it expects that <code class="notranslate">self._key</code> is instance of <code class="notranslate">RSAPrivateKey</code>. Furthermore, this (opaque) exception is followed by many more exceptions of type "TypeError: catching classes that do not inherit from BaseException is not allowed". See reproduction for a complete crash log.</p>
<p dir="auto"><code class="notranslate">cryptography</code> library load_pem_private_key  <a href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/" rel="nofollow">documentation</a> explicitly states that "Many serialization formats support multiple different types of asymmetric keys and will return an instance of the appropriate type. You should check that the returned key matches the type your application expects when using these methods."</p>
<p dir="auto">I propose that the type of the returned key should be checked and appropriate errors raised if the key type is not supported. This would inform the user that the problem they are facing is not a bug in celery or their implementation, but rather that their certificates are not supported by celery.</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://github.com/celery/celery/discussions">discussions forum</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="https://docs.celeryq.dev/en/master/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"> 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>
<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None that I could find</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None that I could find</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ celery --version
5.0.5 (singularity)"><pre class="notranslate"><code class="notranslate">$ celery --version
5.0.5 (singularity)
</code></pre></div>
<p dir="auto"><code class="notranslate">cryptography==37.0.4</code></p>
<h1 dir="auto">Steps to Reproduce</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="app = Celery('test', include=[])
broker_use_ssl = {
        'keyfile': 'broker_client.key',  # private key is ECDSA signed
        'certfile': 'broker_client.crt',
        'ca_certs': 'root.pem',
        'cert_reqs': ssl.CERT_REQUIRED
}

app.conf.update(
        broker_use_ssl=broker_use_ssl,
        security_key='private.key',
        security_certificate='public.crt',
        security_cert_store='security_store/*.pem
)

app.setup_security()
app.start()"><pre class="notranslate"><code class="notranslate">app = Celery('test', include=[])
broker_use_ssl = {
        'keyfile': 'broker_client.key',  # private key is ECDSA signed
        'certfile': 'broker_client.crt',
        'ca_certs': 'root.pem',
        'cert_reqs': ssl.CERT_REQUIRED
}

app.conf.update(
        broker_use_ssl=broker_use_ssl,
        security_key='private.key',
        security_certificate='public.crt',
        security_cert_store='security_store/*.pem
)

app.setup_security()
app.start()
</code></pre></div>
<p dir="auto">This should result in traceback</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" [2022-07-22 14:16:20,309: CRITICAL/MainProcess] Unrecoverable error: EncodeError(SecurityError(&quot;Unable to serialize: TypeError('catching classes that do not inherit from BaseException is not allowed')&quot;))

 Traceback (most recent call last):
   File &quot;/venv/lib/python3.8/site-packages/celery/security/utils.py&quot;, line 24, in reraise_errors
     yield
   File &quot;/venv/lib/python3.8/site-packages/celery/security/key.py&quot;, line 32, in sign
     return self._key.sign(ensure_bytes(data), padd, digest)
 TypeError: sign() takes 3 positional arguments but 4 were given
 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File &quot;/venv/lib/python3.8/site-packages/celery/security/utils.py&quot;, line 24, in reraise_errors
     yield
   File &quot;/venv/lib/python3.8/site-packages/celery/security/serialization.py&quot;, line 39, in serialize
     signature=self._key.sign(body, self._digest),
   File &quot;/venv/lib/python3.8/site-packages/celery/security/key.py&quot;, line 32, in sign
     return self._key.sign(ensure_bytes(data), padd, digest)
   File &quot;/usr/lib/python3.8/contextlib.py&quot;, line 131, in __exit__
     self.gen.throw(type, value, traceback)
   File &quot;/venv/lib/python3.8/site-packages/celery/security/utils.py&quot;, line 25, in reraise_errors
     except errors as exc:
 TypeError: catching classes that do not inherit from BaseException is not allowed
... Above type error repeated many times ..."><pre class="notranslate"><code class="notranslate"> [2022-07-22 14:16:20,309: CRITICAL/MainProcess] Unrecoverable error: EncodeError(SecurityError("Unable to serialize: TypeError('catching classes that do not inherit from BaseException is not allowed')"))

 Traceback (most recent call last):
   File "/venv/lib/python3.8/site-packages/celery/security/utils.py", line 24, in reraise_errors
     yield
   File "/venv/lib/python3.8/site-packages/celery/security/key.py", line 32, in sign
     return self._key.sign(ensure_bytes(data), padd, digest)
 TypeError: sign() takes 3 positional arguments but 4 were given
 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "/venv/lib/python3.8/site-packages/celery/security/utils.py", line 24, in reraise_errors
     yield
   File "/venv/lib/python3.8/site-packages/celery/security/serialization.py", line 39, in serialize
     signature=self._key.sign(body, self._digest),
   File "/venv/lib/python3.8/site-packages/celery/security/key.py", line 32, in sign
     return self._key.sign(ensure_bytes(data), padd, digest)
   File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
     self.gen.throw(type, value, traceback)
   File "/venv/lib/python3.8/site-packages/celery/security/utils.py", line 25, in reraise_errors
     except errors as exc:
 TypeError: catching classes that do not inherit from BaseException is not allowed
... Above type error repeated many times ...
</code></pre></div>