Race condition in send()
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- python
- Ambito
- backend, networking
Direzione di ricerca
Traccia adapter.send(), conditional_headers(), build_response(), update_cached_response() e _load_from_cache() nel flusso della cache e dell’adapter. Riproduci la sequenza a due processi descritta con richieste concorrenti, quindi verifica che una richiesta che ha ricevuto un 304 restituisca comunque la risposta memorizzata nella cache o un normale cache miss, invece di esporre 304 al chiamante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I spotted this while using tox -vvv -p all, so via pip, since pip==26.1.
The issue with tox -p all is that it can run multiple versions of Python (in my config from 3.10 to 3.14), in parallel, I bet some with zstd some without.
TL;DR:
- pip wants to query /simple/setuptools/
- Cache is checked, an etag is found in the cache.
- The HTTP request with an If-None-Match is sent.
- In the meantime the cache gets modified, from
Accept-Encoding: gzip, deflatetoAccept-Encoding: gzip, deflate, zstdor the other way around, by another process. - The HTTP response arrives, it's a
304 Not Modified, the cache has to be updated, but this time it does no longer loads, and the 304 itself is returned.
In details:
It all starts in those two lines of adapter.send():
request.headers.update(self.controller.conditional_headers(request))
resp = super().send(request, stream, timeout, verify, cert, proxies)
Here conditional_headers does a _load_from_cache which can succeed, let say it succeed.
Then super().send() will eventually call adapter.build_response() with a 304 Not Modified so build_response calls self.controller.update_cached_response which runs another _load_from_cache, which can fail if the cache was modified by another process. Let's say it fails it runs this code:
if not cached_response:
# we didn't have a cached response
return response
So the 304 response is returned, up to the user. In case of pip an exception is raised because the answer don't have a Content-Type. But pip or not, the user just did a get with no If-None-Match so he does not expect a 304, either a cache hit (hopefully 200 OK) or a cache miss (hopefully 200 OK) but never a 304.
The chronology with two processes
It think it looks like this, [1] and [2] denoting two distinct processes:
- [1] runs a
requests.get("https://pypi.org/simple/setuptools/") - [2] runs a
requests.get("https://pypi.org/simple/setuptools/") - [1] Read the cache, extract an ETag from the cache
- [2] Read the cache, extract an ETag from the cache
- [1] Sends the HTTP request with If-None-Match
- [2] Sends the HTTP request with If-None-Match
- [1] Gets a response,
adapter.build_responsecallsself.controller.update_cached_response(), changing the headers on disk. TheAccept-Encodingin my case. - [1] Returns the cached response.
- [2] Gets a response,
adapter.build_responsecallsself.controller.update_cached_response()which calls_load_from_cachewhich refuses to load because the headers has changed (Varytells the answer varies onAccept-Encodingand theAccept-Encodingchanged),update_cached_responsereturns the 304 response.build_responsereturns the 304 response. The user gets a304, which is unexpected.
- Lingua principale
- Python
- Stelle
- 505
- Fork
- 153
- Merge medio
- 5g 6h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di psf/cachecontrol
-
Cache Deserialization (part two) -- warning message incorrect?Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
psf/cachecontrol#209 · 5 commenti ·
-
HTTP 302 Found responses with Cache Headers not being cachedForse già presa @cburroughs l’ha presa 279 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
psf/cachecontrol#384 · 18 commenti ·
-
Head request is not cached even with cacheable_methods=("GET", HEAD") without a previous GETForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
psf/cachecontrol#337 · 6 commenti ·
-
Investigate failure to load caches above `2^32 - 1` bytesForse di nuovo libera @woodruffw l’ha presa 852 giorni fa e non c’è nessuna pull request aperta. Aperta
psf/cachecontrol#336 · 4 commenti · 1 reazione · 1 assegnatario ·
-
The new SeparateBodyFileCache design makes updates/reads non-atomicForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
psf/cachecontrol#324 · 4 commenti ·
Tutte le issue di psf/cachecontrol
Issue simili
-
SSM GetParameter throttling during concurrent workflow launchesForse già presa @alexiswl l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
-
[Bug] Dev image build fails: `npm install` in the root Dockerfile runs out of memory (exit 134)Forse già presa @andest01 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Rename FunctionalRole BOT_DEV to DEV_STAFFForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaenhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
pesu-dev/discord_bot#97 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
gradio-app/gradio#13964 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 93/100
BSData/horus-heresy-3rd-edition#3232 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno