What happened?
When using cdsapi.Client() to retrieve data, asyncio logs multiple ERROR-level messages about unclosed aiohttp client sessions. These
appear during garbage collection and create noise in application logs, even though data retrieval completes successfully.
Environment
- cdsapi version: [your version, e.g., 0.7.x]
- Python version: 3.12
- OS: Linux (AWS Batch container)
Steps to Reproduce
import cdsapi
client = cdsapi.Client()
client.retrieve(
'sis-agrometeorological-indicators',
{
'variable': '2m_temperature',
'year': '2024',
'month': '01',
'day': '01',
'version': '2_0',
},
'output.zip'
)
Observed Behavior
2026-01-19 06:37:54,906 - asyncio - ERROR - Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fcda4d5a9f0>
2026-01-19 06:37:54,906 - asyncio - ERROR - Unclosed connector
connections: ['deque([...])']
connector: <aiohttp.connector.TCPConnector object at 0x7fcda4b9c740>
These errors appear:
- Immediately after Client() initialization (before any API requests)
- At the end of the process during garbage collection
Expected Behavior
The library should properly close its internal aiohttp sessions, either:
- By exposing a close() method on the Client
- By implementing context manager support (enter/exit)
- By properly cleaning up sessions internally
Workaround
Currently, users can suppress these logs with a logging filter, but this isn't ideal:
import logging
class UnclosedSessionFilter(logging.Filter):
def filter(self, record):
return "Unclosed client session" not in record.getMessage()
logging.getLogger("asyncio").addFilter(UnclosedSessionFilter())
Additional Context
The sessions appear to be created by ecmwf.datastores.legacy_client during initialization. The cdsapi.Client object has a session
attribute (requests.Session) and a client attribute (ecmwf.datastores.client.Client), but neither exposes the internal aiohttp sessions
for cleanup.
What are the steps to reproduce the bug?
import cdsapi
client = cdsapi.Client()
client.retrieve(
'sis-agrometeorological-indicators',
{
'variable': '2m_temperature',
'year': '2024',
'month': '01',
'day': '01',
'version': '2_0',
},
'output.zip'
)
Version
v0.7.x
Platform (OS and architecture)
Linux (AWS Batch container)
Relevant log output
2026-01-19 06:37:54,906 - asyncio - ERROR - Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fcda4d5a9f0>
2026-01-19 06:37:54,906 - asyncio - ERROR - Unclosed connector
connections: ['deque([...])']
connector: <aiohttp.connector.TCPConnector object at 0x7fcda4b9c740>
Accompanying data
No response
Organisation
CarbonSpace
What happened?
When using cdsapi.Client() to retrieve data, asyncio logs multiple ERROR-level messages about unclosed aiohttp client sessions. These
appear during garbage collection and create noise in application logs, even though data retrieval completes successfully.
Environment
Steps to Reproduce
Observed Behavior
These errors appear:
Expected Behavior
The library should properly close its internal aiohttp sessions, either:
Workaround
Currently, users can suppress these logs with a logging filter, but this isn't ideal:
Additional Context
The sessions appear to be created by ecmwf.datastores.legacy_client during initialization. The cdsapi.Client object has a session
attribute (requests.Session) and a client attribute (ecmwf.datastores.client.Client), but neither exposes the internal aiohttp sessions
for cleanup.
What are the steps to reproduce the bug?
Version
v0.7.x
Platform (OS and architecture)
Linux (AWS Batch container)
Relevant log output
Accompanying data
No response
Organisation
CarbonSpace