-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
Reading the official aiohttp documentation: https://docs.aiohttp.org/en/stable/client_reference.html
I optimized my code to have a single ClientSession
within my app to take advantage of connection pooling
class My_class:
_clientSession= aiohttp.ClientSession()
async def my_method():
async with self._clientSession.ws_connect(uri) as ws:
await ws.receive_json()
...
await ws.send_json(stuff)
my_method
is invoked twice - to different web sockets, over TLS simultaneously.
I get randomly served with a Uncaught exception in callback: (-28928, 'MBEDTLS_ERR_SSL_BAD_INPUT_DATA')
.
Creating the ClientSession
within my_method
completely resolves the issue - but at the expense of connection pooling. I strongly suspect a racing condition tied to the pooling.
This is happening on a pico 2 w running 1.25.0
Activity
Carglglz commentedon Jun 4, 2025
Can you test this without TLS?, Can you test unix port?
As a workaround
asyncio.Lock
may help https://docs.micropython.org/en/latest/library/asyncio.html#class-lock,Concurrency and TLS is tricky, if you want to debug this for
mbedTLS
add atmbedtls_config_port.h
FuNK3Y commentedon Jun 11, 2025
Thank you for your answer.
As a workaround, I create a
ClientSession
per remote endpoint and it works well enough.I sadly can't test without TLS. This bug is out of my depth to troubleshoot - I raised an issue to give a chance to others to correlate their observations with mine.