Connection hangs/does not timeout after 350 seconds.

Aperta
#798 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python

Direzione di ricerca

Inizia riproducendo la richiesta HTTP/2 di AsyncClient attraverso un AWS VPC NAT gateway, utilizzando i dettagli relativi a timeout e healthcheck periodico riportati nel report. Analizza come la connessione gestisce il RST del NAT gateway dopo 350 secondi; il lavoro è completato quando il comportamento viene risolto andando in timeout nel punto appropriato oppure mantenendo la connessione con traffico keepalive.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Originally opened by @mittalsuraj18 on 2023-12-04 06:24:56 in encode/httpx

Discussed in https://github.com/encode/httpx/discussions/2968

Originally posted by mittalsuraj18 December 1, 2023
When an application is running on an AWS VPC and using NAT gateway to communicate, there is a specific behavior in NAT gateway which is described here https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-troubleshooting.html as such

Internet connection drops after 350 seconds
Problem

Your instances can access the internet, but the connection drops after 350 seconds.
Cause

If a connection that's using a NAT gateway is idle for 350 seconds or more, the connection times out.

When a connection times out, a NAT gateway returns an RST packet to any resources behind the NAT gateway that attempt to continue the connection (it does not send a FIN packet).
Solution

To prevent the connection from being dropped, you can initiate more traffic over the connection. Alternatively, you can enable TCP keepalive on the instance with a value less than 350 seconds.

For example, if i have a single connection. and do something like,

client = AsyncClient(base_url=BASE_URL, http2=True)
_ = await client.get("/", timeout=1200)

The connection does not respond to RST packet. And times out after 1200 seconds instead of 350 seconds.

The behavior should have been either of the following

  1. Timeout at 350 seconds
  2. Periodically send keepalive packet to make sure NAT gateway does not timeout.

How i currently have solved it is by doing a periodic call every 60 seconds, which just calls a healtcheck endpoint of the same baseurl, to use the same connection.

Lingua principale
Python
Stelle
1.6k
Fork
103
Merge medio
1g 19h
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pydantic/httpx2

Tutte le issue di pydantic/httpx2

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.