From c6311acffb3251b4ccf11cad3c4e64218bbcfad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Tue, 4 Aug 2026 17:59:13 -0600 Subject: [PATCH] =?UTF-8?q?fix(sheets):=20timeout=20duro=20en=20llamadas?= =?UTF-8?q?=20a=20Google=20=E2=80=94=20un=20cuelgue=20congelaba=20el=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gspread usa requests sin timeout: si la red al API de Google se cuelga, la llamada síncrona bloquea el event loop de uvicorn y el bot COMPLETO deja de responder (síntoma observado: último log = respuesta de OpenAI, luego silencio total, cotizador muerto). Con timeout (10s conexión, 20s lectura) la llamada truena, cae en los except existentes ('No pude generar el reporte...') y el bot sigue vivo. Co-Authored-By: Claude Opus 4.8 --- src/services/sheets.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/sheets.py b/src/services/sheets.py index e35047f..3629b9a 100644 --- a/src/services/sheets.py +++ b/src/services/sheets.py @@ -108,6 +108,11 @@ def _get_client() -> gspread.Client | None: return None creds_dict = json.loads(creds_json) _gc = gspread.service_account_from_dict(creds_dict) + # Timeout duro (conexión, lectura) a TODA llamada HTTP a Google. + # gspread usa requests SIN timeout por default: si la red al API de + # Google se cuelga, la llamada síncrona bloquea el event loop y el + # bot COMPLETO deja de contestar (cotizador incluido). + _gc.set_timeout((10, 20)) return _gc