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 SIGKILL
  • Failed with result 'timeout'

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.

Durante shutdown:

  1. Se marca shutting_down=true en memoria.
  2. Se registran logs operativos de cierre.
  3. Nuevas solicitudes (excepto /health) reciben 503 controlado.
  4. /health mantiene 200 para probes, con status=shutting_down y shutting_down=true.
  5. El shutdown del servidor se inicia en hilo daemon separado.
  6. Se arma watchdog bounded (20s) para forzar salida limpia solo si serve_forever() no retorna.
  7. Al salir de serve_forever, se ejecuta server_close() y liberacion de PID lock.
  • shutdown requested
  • server shutdown initiated
  • shutdown fallback armed
  • Gateway server closing...
  • PID lock released
  • server closed
  • clean exit
  • 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.

Antes y despues del restart:

Terminal window
curl -s http://127.0.0.1:8008/health | jq .
curl -s http://127.0.0.1:8008/v1/models | jq .

Reinicio manual:

Terminal window
sudo systemctl restart ailab-gateway

Verificar ausencia de timeout/SIGKILL:

Terminal window
journalctl -u ailab-gateway -n 120 --no-pager

No deberia aparecer:

  • State 'stop-sigterm' timed out
  • signal SIGKILL
  • Failed with result 'timeout'

Si se detecta regresion:

  1. Revertir commit de esta fase.
  2. Reiniciar ailab-gateway.
  3. Revalidar /health, /v1/models, /runtime/health/summary y logs.