Skip to content

Close WSGI response iterables on teardown and errors - #204

Open
jaelliot wants to merge 6 commits into
ioflo:mainfrom
jaelliot:fix/wsgi-iterator-close-review
Open

jaelliot wants to merge 6 commits into
ioflo:mainfrom
jaelliot:fix/wsgi-iterator-close-review

Conversation

@jaelliot

@jaelliot jaelliot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Close WSGI response iterables on completion, connection teardown, reset, and error paths. Close failed streaming connections without sending a successful chunked terminator.

Keep the native and Pyodide CI jobs on Python 3.14, constrain multidict to the major version that preserves HIO's duplicate-key contract, and retry a TCP connection when the socket reports a transient not-connected error while resolving its peer.

Validation

  • 15 TCP tests and 17 dictionary and WSGI lifecycle tests passed locally, including transient reconnect errors and write failures during headers, body, and the final chunk.
  • The new WSGI write-failure and TCP reconnect tests failed against their preceding implementations and passed with the fixes. Dictionary tests failed with multidict 7.2.1 and passed with 6.9.1; the updated dependency constraint resolves to 6.9.1.
  • Hosted CI passed the native test matrix on macOS, Ubuntu, and Windows, plus the Chrome, Firefox, and Node WebAssembly jobs and the documentation build.
  • The author reviewed the Python changes and acknowledged intentional structural changes before push. The full local suite was skipped because filing tests delete fixed test directories; CI runs it in isolated environments. The local push hook reported that pip-licenses was not installed.

Retain the application iterable so completion, reset, and teardown invoke
its close method exactly once, including when iter() returns another object.
Log application cleanup errors without preventing connection teardown.

Add nine lifecycle cases covering native teardown, immediate generator
cleanup, completion, persistent reuse, and cleanup exceptions.

Validation: 56 HTTP tests pass. Full suite: 266 pass, one skipped,
with the same seven filesystem-fixture failures as the unpatched baseline.
@jaelliot
jaelliot marked this pull request as ready for review November 19, 2026 23:35
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the WSGI response lifecycle changes.

No open issues 🎉

What changed in this PR

This PR strengthens WSGI response lifecycle handling in the native HTTP server, releasing application resources and preventing failed streams from receiving a successful chunked terminator.

Changes:

  • Track and close application iterables exactly once across completion, reset, teardown, and error paths.
  • Add regression tests for cleanup, persistent connections, iterator creation errors, and write failures during headers, body, and final-chunk transmission.
File Description
tests/​core/​http/​test_wsgi_lifecycle.py Tests iterable cleanup, failure handling, teardown, and connection reuse.
src/​hio/​core/​http/​serving.py Adds iterable ownership, repeat-safe cleanup, and error-path handling.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants