question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TLSListener: exception during handshake

See original GitHub issue

Run the TLSListener example, but comment out the line that calls load_verify_locations. Because the certificate is self-signed, the client will throw ssl.SSLCertVerificationError. However, the server also throws an exception:

Traceback (most recent call last):
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/tls.py", line 98, in _call_sslobject_method
    result = func(*args)
  File "/usr/lib/python3.8/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLSyscallError: Some I/O error occurred (_ssl.c:1108)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "server.py", line 25, in <module>
    run(main)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_core/_eventloop.py", line 52, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 160, in run
    return native_run(wrapper(), debug=debug)
  File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
    return future.result()
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 155, in wrapper
    return await func(*args)
  File "server.py", line 23, in main
    await listener.serve(handle)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/tls.py", line 208, in serve
    await self.listener.serve(handler_wrapper, task_group)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/stapled.py", line 113, in serve
    await tg.spawn(listener.serve, handler, task_group)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 438, in __aexit__
    raise exceptions[0]
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 466, in _run_wrapped_task
    await func(*args)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/abc/sockets.py", line 109, in serve
    await task_group.spawn(handler, stream)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 438, in __aexit__
    raise exceptions[0]
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 466, in _run_wrapped_task
    await func(*args)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/tls.py", line 204, in handler_wrapper
    wrapped_stream = await TLSStream.wrap(stream, ssl_context=self.ssl_context,
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/tls.py", line 92, in wrap
    await wrapper._call_sslobject_method(ssl_object.do_handshake)
  File "/home/yannik/.local/lib/python3.8/site-packages/anyio/streams/tls.py", line 117, in _call_sslobject_method
    raise BrokenResourceError from exc
anyio.BrokenResourceError

There seems to be no way to catch this exception before it crashes the server. I can put a try-except around await listener.serve(handle) and restart the server after the exception occurs, but at this point all clients have been disconnected already.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kinnaycommented, Jan 31, 2021

Yes, sorry, looks good to me.

0reactions
agronholmcommented, Jan 30, 2021

@kinnay you haven’t commented yet. Have you looked at the PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rehash: How to Fix the SSL/TLS Handshake Failed Error
The TLS Handshake Failed error can originate from the client or the server, here's a guide for fixing the problem for both users...
Read more >
Resolve the client SSL/TLS negotiation error when connecting ...
A client TLS negotiation error means that a TLS connection initiated by the client was unable to establish a session with the load...
Read more >
SSL Handshake Failures - Baeldung
During a handshake, the client will present a list of possible ciphers to use and the server will respond with a selected cipher...
Read more >
TLS/SSL troubleshooting information - IBM
The cause of the exception is listed as the first item within each section. ... SSLHandshakeException: Remote host closed connection during handshake at ......
Read more >
How to diagnose and fix SSL handshake error: no cipher ...
CAUSE. This error is usually caused by two reasons: The keystore in the HTTPS Listener does not contain the private key required for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found