Skip to content

Close callback buffers even when caching fails - #495

Closed
liuyinchu wants to merge 1 commit into
psf:masterfrom
liuyinchu:fix-callback-failure-cleanup
Closed

liuyinchu wants to merge 1 commit into
psf:masterfrom
liuyinchu:fix-callback-failure-cleanup

Conversation

@liuyinchu

Copy link
Copy Markdown

CallbackFileWrapper._close skips its cleanup when the cache callback raises. A cache write error or interruption therefore leaves the temporary file open and the callback attached; reading EOF again can call it again.

Run the existing callback-reference and temporary-file cleanup in finally. Keep the original exception propagation and callback data unchanged. Add tests using real http.client.HTTPResponse objects for empty/nonempty bodies, successful callbacks, OSError, and KeyboardInterrupt.

Validation on Linux, CPython 3.12.14:

  • Original implementation: four new regressions fail, two controls pass.
  • Final full suite: 122 passed, rerun against current master before submission.
  • Repository Ruff/mypy lint, changed-file format, wheel/sdist build and strict Sphinx build pass.
  • A localhost requests/urllib3 consumer with a failing cache backend confirms file closure/unlink and preserved error cause.

This is deliberately narrow: a retained traceback can still hold the existing mmap view. Native Windows/macOS and the other Python versions have not been tested locally.

AI disclosure: prepared with OpenAI Codex assistance, including a separate automated review and consumer probe. No human manual review is claimed.

@woodruffw woodruffw closed this Nov 3, 2026
@psf psf locked as spam and limited conversation to collaborators Nov 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants