Skip to content

aiohttp - incorrect handling of connection pooling with web sockets. #1018

Open
@FuNK3Y

Description

@FuNK3Y

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions