Skip to content

Stale cache refresh fails on Windows with PyPy #497

Closed

Description

@notatallshaw

On PyPy on Windows, refreshing a stale response in a file-backed separate-body cache can fail because the old body file remains open. In pip this leaves new headers beside the old body (pypa/pip#14431). urllib3 2.8 exposes the mismatch by enforcing the new Content-Length and raising IncompleteRead when the old body is shorter; it does not cause the open-file bug.

CacheController opens the body during cache lookup but does not close the response when cached_request() rejects it, conditional_headers() reads its validators, or deserialization fails. A stale request can leave two handles open.

Expected: close discarded separate-body responses while leaving returned cache hits and in-memory cached responses open.

Related: #302 assumed the response would close the file. #343 addresses conditional_headers() but misses the other discard paths.

Activity

  1. woodruffw commented on Nov 16, 2026

    @woodruffw
    Member

    Thanks, I merged #498 and part of #502 and I've shipped a new CacheControl release.

  2. notatallshaw commented on Nov 16, 2026

    @notatallshaw
    ContributorAuthor

    Speedy, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions