Repository navigation
Description
Summary
The README "Creating a Client" section documents two client options that the default requests backend (use_httpx=False) does not honor. The httpx backend honors both:
- Context manager /
close(). The README sayswith InferenceGatewayClient("http://localhost:8080/v1") as client:is used "to ensure the underlying HTTP client is closed".close()(inference_gateway/client.pylines 147-150) only does something whenself.use_httpxis true. On the default backend it returns without callingself.session.close(), so therequests.Sessionand its pooled connections are never released. timeout. The README showstimeout=60.0as a supported option, and the constructor documents it as "Request timeout in seconds". Non-streaming calls get the timeout from_make_request(lines 161-162). The streaming methods bypass_make_requestand callself.session.post(..., stream=True)without atimeout(lines 482-487, 699-704, 1168-1173). As a result,create_chat_completion_stream,create_response_streamandcreate_message_streamhave no timeout at all on the default backend.tests/test_client.py::test_create_chat_completion_stream_errorcurrently asserts that this call is made withouttimeout.
On the httpx backend, close() closes the httpx.Client, and httpx.Client(timeout=timeout) also applies the timeout to streams.
Steps to Reproduce
- Run
with InferenceGatewayClient("http://localhost:8080/v1") as client: client.list_models(). - After the block exits,
len(client.session.adapters["http://"].poolmanager.pools)is still1, becauseself.session.close()was never called. - Create
client = InferenceGatewayClient("http://localhost:8080/v1", timeout=5.0). - Call
client.create_chat_completion_stream(...)against an upstream that accepts the connection but stops sending data.
Expected Behavior
Leaving the with block (or calling close()) closes the requests.Session, just as it closes the httpx.Client. The configured timeout applies to streaming requests on the requests backend, as it does on the httpx backend.
Actual Behavior
On the default backend, close() does nothing, so the session's connections stay open after the context manager exits. Streaming requests are sent without a timeout, so a stalled upstream blocks the caller indefinitely instead of failing after timeout seconds.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
edenreich commentedon Sep 25, 2026
@infer Can you fix this?
inference-gateway-maintainer commentedon Sep 25, 2026
Model:
ollama_cloud/glm-5.3-flash· View JobTodos
Pull Request
#138
✅ Infer Result: Success
Fixed and pushed. PR: #138
Summary of changes
Bug 1 -
close()was a no-op on the default backend (inference_gateway/client.py):close()now callsself.session.close()for therequestsbackend, so therequests.Sessionand its pooled connections are released when the context manager exits orclose()is called - matching thehttpxbackend.Bug 2 - streaming calls ignored
timeout:create_chat_completion_stream,create_response_streamandcreate_message_streamnow passtimeout=self._timeouttoself.session.post(..., stream=True), so the configured timeout applies to streaming requests on the default backend (as it already did for non-streaming calls via_make_request, and onhttpx). A stalled upstream now fails aftertimeoutseconds instead of blocking forever.Tests (
tests/test_client.py):test_create_chat_completion_stream_error, which previously asserted the call was made withouttimeout) to expecttimeout=30.0test_close_closes_http_backendsverifyingclose()closes both therequests.Sessionand thehttpx.ClientValidation:
task test- 42 passed, 1 xfailed (pre-existing strict xfail for schemas#29);task lint- black, isort, mypy all clean. No docs ticket needed (the README already documents both options; the fix makes the default backend comply with the documented behavior) and no downstream repos are affected.The issue is on the Roadmap 2026 board with Status = QA.
Model:
ollama_cloud/glm-5.3-flash· Exit Code:0· Duration: 4m 48sTokens: 2,656,885 in · 21,543 out · 2,678,428 total (47 requests)
Tool calls: 47 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
inference-gateway-releaser commentedon Sep 26, 2026
🎉 This issue has been resolved in version 0.21.1 🎉
The release is available on GitHub release
Your semantic-release bot 📦🚀