Skip to content

Add aiohttp_evicted_sessions to HTTPSessionManager#3805

Open
cyc60 wants to merge 2 commits intoethereum:mainfrom
cyc60:aiohttp-evicted-sessions
Open

Add aiohttp_evicted_sessions to HTTPSessionManager#3805
cyc60 wants to merge 2 commits intoethereum:mainfrom
cyc60:aiohttp-evicted-sessions

Conversation

@cyc60
Copy link

@cyc60 cyc60 commented Jan 28, 2026

What was wrong?

Still receive Unclosed client session messages

Received interrupt signal 2, exiting...
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fb6d9a86a20>

Disconnect is already implemented.

class ExtendedAsyncBeacon(AsyncBeacon):
    async def disconnect(self) -> None:
        """
        Close aiohttp sessions for provider.
        Got `Unclosed client session` otherwise.
        https://github.com/ethereum/web3.py/issues/3524
        """
        cache = self._request_session_manager.session_cache
        for _, session in cache.items():
            await session.close()
        cache.clear()

Related to Issue #
#3524
Closes #

How was it fixed?

The issue is with evicted sessions — they cannot be force-closed from client code. They remain open for the duration of the request_timeout.

Added aiohttp_evicted_sessions to HTTPSessionManager to track currently open evicted sessions.

Disconnect should now look like this:

async def disconnect(self) -> None:
    """
    Close aiohttp sessions for provider.
    Got `Unclosed client session` otherwise.
    https://github.com/ethereum/web3.py/issues/3524
    """
    cache = self._request_session_manager.session_cache
    for _, session in cache.items():
        await session.close()
    evicted_sessions = self._request_session_manager.aiohttp_evicted_sessions
    for session in evicted_sessions:
        await session.close()
    cache.clear()

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant