psf / psf/cachecontrol

The new SeparateBodyFileCache design makes updates/reads non-atomic

Open
#324 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
505
Forks
149
Avg merge
2d 13h
Merged PRs (30d)
7

Description

The problem

Scenario 1

Program crashes after writing metadata but before writing body. Now the cache thinks the body is empty.

Scenario 2

Multiple processes using the same cache directory. Process A writes metadata, but not yet body. Process B gets metadata, then gets body, and now it thinks the body is empty.

Workarounds

For pip I added logic that basically pretends a cache entry is missing if it doesn't have both body and metadata files.

Solutions

Probably need both a new API that involves writing and reading both at once, and an implementation that makes sure that's atomic. See also the somewhat related #325.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the SeparateBodyFileCache design described in the issue and the related discussion in #325. Define how metadata and body reads and writes should behave when a process crashes or multiple processes share a cache directory; done means incomplete entries are not observed as valid cache entries and both operations are atomic.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.