Skip to content

fix: close WSGI response iterables after consumption - #369

Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
Azure:devfrom
Shubham-Padkonde:fix/close-wsgi-response-iterables
Open

Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
Azure:devfrom
Shubham-Padkonde:fix/close-wsgi-response-iterables

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

The WSGI adapter consumes the application's response iterable without calling its close() method. File responses can consequently leave their streams open, and framework cleanup callbacks are skipped.

Close the original response iterable in a finally block after consuming it, as required by PEP 3333. This also releases resources when iteration raises, while preserving the original iteration error when cleanup succeeds. Iterables without close() continue to work.

Validation: 890 tests pass and two are skipped on Python 3.13. New regressions cover a real Werkzeug file wrapper, an empty response, and an iteration error; all three fail before the fix. Flake8 E/F/W checks pass. The docstring plugin reports the same two pre-existing findings on the original and modified WSGI module.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

1 participant