Problema detectado
Section titled “Problema detectado”En reinicios previos, ailab-gateway recibia SIGTERM pero no cerraba dentro del timeout de systemd, terminando en SIGKILL.
Sintomas observados en logs:
Received signal, shutting down gracefully...State 'stop-sigterm' timed out. Killing.Killing process ... with signal SIGKILLFailed with result 'timeout'
Causa probable
Section titled “Causa probable”Uso de server.shutdown() desde el mismo hilo del manejador de señal y salida abrupta (sys.exit) antes de cerrar el servidor de forma ordenada.
Comportamiento implementado
Section titled “Comportamiento implementado”Durante shutdown:
- Se marca
shutting_down=trueen memoria. - Se registran logs operativos de cierre.
- Nuevas solicitudes (excepto
/health) reciben503controlado. /healthmantiene200para probes, constatus=shutting_downyshutting_down=true.- El shutdown del servidor se inicia en hilo daemon separado.
- Se arma watchdog bounded (20s) para forzar salida limpia solo si
serve_forever()no retorna. - Al salir de
serve_forever, se ejecutaserver_close()y liberacion de PID lock.
Logs esperados
Section titled “Logs esperados”shutdown requestedserver shutdown initiatedshutdown fallback armedGateway server closing...PID lock releasedserver closedclean exit
Metricas
Section titled “Metricas”ailab_gateway_shutdown_rejections_total: requests rechazadas durante ventana de shutdown.ailab_gateway_clean_shutdown_total: contador de apagados limpios.ailab_gateway_shutdown_fallback_total: salidas forzadas por watchdog cuando el cierre graceful se estanca.
Validacion operativa
Section titled “Validacion operativa”Antes y despues del restart:
curl -s http://127.0.0.1:8008/health | jq .curl -s http://127.0.0.1:8008/v1/models | jq .Reinicio manual:
sudo systemctl restart ailab-gatewayVerificar ausencia de timeout/SIGKILL:
journalctl -u ailab-gateway -n 120 --no-pagerNo deberia aparecer:
State 'stop-sigterm' timed outsignal SIGKILLFailed with result 'timeout'
Rollback
Section titled “Rollback”Si se detecta regresion:
- Revertir commit de esta fase.
- Reiniciar
ailab-gateway. - Revalidar
/health,/v1/models,/runtime/health/summaryy logs.