Repository navigation
fix(ci): CLIENTES_POST_TIMEOUT_MS para evitar DB_TIMEOUT en E2E - #40
Closed
casasleonj wants to merge 1 commit into
Closed
casasleonj wants to merge 1 commit into
casasleonj wants to merge 1 commit into
Conversation
…/clientes El POST /api/clientes envuelve executeSerializableWithRetry en un timeout global de 25s. En CI el contenedor PostgreSQL arranca frío y la transacción Serializable con 3 reintentos (15s + 5s maxWait cada uno) supera el timeout. - Timeout configurable via env var CLIENTES_POST_TIMEOUT_MS (default 25s). - CI setea 60s en el job e2e para dar margen al cold start. - Producción/Vercel sigue con 25s (comportamiento sin cambios).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Oct 7, 2026
Merged
casasleonj
added a commit
that referenced
this pull request
Oct 7, 2026
…request ya terminada (R2, PR #140) (#281) Hallazgo histórico: PR #140 Estado verificado: main @ a3316bd Brecha actual: el timer de 25s (`setTimeout(..., 25_000)` sobre timeoutPromise) se creaba ANTES de parsear/validar el body. Una request inválida (Zod rechaza) retornaba 400 de inmediato, pero el timer seguía vivo: 25s después disparaba `reject(new Error('DB_TIMEOUT'))` sobre una promesa que ya nadie esperaba (el Promise.race nunca se alcanzó, o ya se resolvió) → unhandledRejection: DB_TIMEOUT. Nunca había `clearTimeout` en ningún path. Coincide con el patrón exacto documentado en Known Issue #20 de AGENTS.md ("2x unhandledRejection: Error: DB_TIMEOUT" en shard 1 de CI). Invariante aplicado: un timeout pertenece al trabajo que protege. Secuencia: validar request → crear timeout → ejecutar operación DB → cancelar timeout siempre (finally). Cambio: el `setTimeout` se mueve a después de `ClienteCreateSchema.safeParse` (solo se crea si el body es válido y vamos a tocar la DB). El handle se guarda en `timeoutId` (declarado antes del try para que el `finally` lo alcance) y se cancela con `clearTimeout(timeoutId)` en un `finally` que cubre todos los paths de retorno (400 temprano no llega a crear timer; 200/201 éxito; 500 DB_TIMEOUT; 500 error genérico). No se amplía el timeout (sigue en 25s), no se toca la estrategia de reintentos de `executeSerializableWithRetry`, no se cambian límites de Vercel. Pruebas — src/app/api/clientes/__tests__/timeout-lifecycle.test.ts (nuevo, unitario con fake timers, sin DB — executeSerializableWithRetry mockeado): - Caso A: body inválido → 400 inmediato; avanzar 30s no genera unhandledRejection (mutation check: falla contra el código viejo con exactamente `Error: DB_TIMEOUT` capturado — reproduce el bug real). - Caso B: operación exitosa → avanzar 30s después no genera unhandledRejection (el timer quedó cancelado). - Caso C: la "DB" nunca resuelve → al cumplirse los 25s, respuesta controlada 500 "tardó demasiado", sin colgarse. Validación local: tsc --noEmit limpio, eslint . limpio (0 issues), npm run test 355/355 archivos / 3481/3481 tests (incluye los 3 nuevos). npm run test:integration no se pudo correr en esta sesión (sin Docker/ Postgres disponible) — no aplica aquí de todos modos: este fix no toca Postgres, todo el comportamiento se prueba con fake timers + mocks. Fuera de alcance: aumentar el timeout, modificar retries, modificar estrategia de transacciones, cambiar límites de Vercel. PR #40 (que pedía subir CLIENTES_POST_TIMEOUT_MS a 60s) queda superado por este fix y debe cerrarse tras integrar este PR. Claude-Session: https://claude.ai/code/session_01M3dEHC9mqKDgGch3W866vq Co-authored-by: Claude <[email protected]>
Owner
Author
|
Este PR se cierra sin fusionar. Su contenido fue reevaluado contra el main actual y los cambios todavía válidos fueron recuperados mediante los PR nuevos del ALS. Se conserva únicamente como evidencia histórica. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema
En CI el POST /api/clientes tira
DB_TIMEOUTporque el timeout global de 25s es menor que lo que puede tardar la transacción Serializable con 3 reintentos (15s timeout + 5s maxWait por intento) cuando PostgreSQL en docker arranca frío.Cambio
src/app/api/clientes/route.ts: timeout configurable viaCLIENTES_POST_TIMEOUT_MS(default 25s)..github/workflows/ci.yml: seteaCLIENTES_POST_TIMEOUT_MS=60000en el job e2e.Riesgo
Ninguno para producción: Vercel sigue usando el default de 25s. Solo cambia CI.