Connection hangs/does not timeout after 350 seconds.

Abierto
#798 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python

Línea de trabajo

Empieza reproduciendo la solicitud HTTP/2 de AsyncClient a través de un AWS VPC NAT gateway, utilizando los detalles de timeout y healthcheck periódico indicados en el informe. Investiga cómo gestiona la conexión el RST del NAT gateway después de 350 segundos; se considera terminado cuando el comportamiento se aborda agotando el tiempo de espera en el punto adecuado o manteniendo la conexión con tráfico keepalive.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.6k
Forks
103
Merge medio
1 d 19 h
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pydantic/httpx2

Todos los issues de pydantic/httpx2

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.