Problem
The sync Client has no close() method and no context manager support (__enter__/__exit__). The underlying httpx.Client requires an explicit close() to release the TCP connection pool, but since httpx.Client has no __del__, simply deleting the lightkube Client reference does not close the transport.
This means every Client instance leaks open file descriptors until the process exits or the remote end times them out.
The async GenericClient has the same gap — no aclose() or async with support.
Current workaround
We reach through private attributes to close the httpx transport:
# lightkube.Client._client (GenericSyncClient)._client (httpx.Client)
self._client._client._client.close()
This works but is fragile — it will break if lightkube's internal attribute names change.
Proposed fix
Add close() and context manager support to both Client and AsyncClient:
# Sync
class Client:
def close(self) -> None:
self._client._client.close()
def __enter__(self) -> Self:
return self
def __exit__(self, *args: object) -> None:
self.close()
# Async
class AsyncClient:
async def aclose(self) -> None:
await self._client._client.aclose()
async def __aenter__(self) -> Self:
return self
async def __aexit__(self, *args: object) -> None:
await self.aclose()
Environment
- lightkube 0.21.0
- httpx 0.28.1
- Python 3.14
Problem
The sync
Clienthas noclose()method and no context manager support (__enter__/__exit__). The underlyinghttpx.Clientrequires an explicitclose()to release the TCP connection pool, but sincehttpx.Clienthas no__del__, simply deleting the lightkubeClientreference does not close the transport.This means every
Clientinstance leaks open file descriptors until the process exits or the remote end times them out.The async
GenericClienthas the same gap — noaclose()orasync withsupport.Current workaround
We reach through private attributes to close the httpx transport:
This works but is fragile — it will break if lightkube's internal attribute names change.
Proposed fix
Add
close()and context manager support to bothClientandAsyncClient:Environment