Skip to content

ClientSession inside an aiohttp Server does not support connection pooling #2072

Closed
@alexmac

Description

I've got a aiohttp server that makes multiple http requests to other services in response to its inbound requests, I want to use a ClientSession for each inbound request to handle any cookie state that may be needed across the downstream requests it makes - but this means my server makes no use of connection-pooling/keep-alive when making downstream requests.

I could share a single ClientSession across all inbound requests, but then cookie/header state within the ClientSession would be re-used across inbound requests, which would not be correct. I could perhaps create a SharedClientSession object that handled switching between cookies/headers with a single underlying ClientSession, but that seems like I'm fighting the system.

Is there a supported way to do this? The most elegant way I can imagine would be a single ClientSession per inbound request with a global tcpconnector - except the ClientSession takes ownership and closes it, making it impossible to use in this way.

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationoutdated

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions