Skip to content

fix(client): close requests Session in close() and apply timeout to streaming calls - #138

Merged
edenreich merged 1 commit into
mainfrom
fix/issue-134
Sep 25, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/issue-134

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Resolves #134

Summary

The default requests backend now honors the two client options the README documents but only the httpx backend implemented: close() releases the requests.Session and its pooled connections, and the configured timeout is applied to the three streaming calls, so a stalled upstream fails after timeout seconds instead of blocking the caller indefinitely.

Changes

  • close() now calls self.session.close() on the requests backend (previously a no-op), matching the httpx backend behavior for the context manager / close() path
  • create_chat_completion_stream, create_response_stream and create_message_stream pass timeout=self._timeout to self.session.post(..., stream=True) so the configured timeout applies to streaming requests, as it already did for non-streaming calls via _make_request
  • Updated the five streaming call assertions in tests/test_client.py (including test_create_chat_completion_stream_error, which previously asserted the call was made without timeout) to expect timeout=30.0
  • Added test_close_closes_http_backends regression test verifying close() closes both the requests.Session and the httpx.Client

Tests

  • task test - 42 passed, 1 xfailed (pre-existing strict xfail for schemas#29)
  • task lint - black, isort and mypy all pass

no docs ticket: the README already documents both options; this PR makes the default backend comply with the documented behavior.

…treaming calls

close() now releases the pooled connections of the default requests backend, matching the httpx backend, and the three streaming methods pass the configured timeout to session.post so a stalled upstream fails after timeout seconds instead of blocking forever. Updates the streaming call assertions and adds a close() regression test for both backends.
@inference-gateway-maintainer
inference-gateway-maintainer Bot marked this pull request as ready for review September 25, 2026 22:54
@edenreich
edenreich merged commit 4a1e48f into main Sep 25, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-134 branch September 25, 2026 23:03
inference-gateway-releaser Bot added a commit that referenced this pull request Sep 26, 2026
## [0.21.1](v0.21.0...v0.21.1) (2026-09-26)

### 🐛 Bug Fixes

* **client:** carry HTTP status and error body into InferenceGatewayAPIError ([#139](#139)) ([d58a54f](d58a54f))
* **client:** close requests Session in close() and apply timeout to streaming calls ([#138](#138)) ([4a1e48f](4a1e48f))
* **client:** route health_check and proxy_request to root-level routes ([#136](#136)) ([ec782ca](ec782ca))

### 📚 Documentation

* **readme:** correct MCP_ENABLED env var, provider list, vision reference, and images example ([#137](#137)) ([8cc2ef6](8cc2ef6))
* **readme:** document streaming error behavior parity ([#140](#140)) ([23a1d69](23a1d69))

### 🔧 Miscellaneous

* **deps:** bump claude-code 2.1.278 -> 2.1.280 ([#130](#130)) ([2a73e16](2a73e16))
* **deps:** bump infer CLI v0.205.3 -> v0.208.0 ([#131](#131)) ([703f184](703f184))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.21.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] requests backend: close() leaves the Session open and streaming calls ignore timeout

1 participant