Skip to content

fix(server): add graceful shutdown on SIGTERM and SIGINT to reset connected characters - #105

Open
trexfr-ops wants to merge 2 commits into
Bitcoindefi:mainfrom
trexfr-ops:fix/graceful-shutdown-reset-connected
Open

fix(server): add graceful shutdown on SIGTERM and SIGINT to reset connected characters#105
trexfr-ops wants to merge 2 commits into
Bitcoindefi:mainfrom
trexfr-ops:fix/graceful-shutdown-reset-connected

Conversation

@trexfr-ops

Copy link
Copy Markdown

Description

Closes #26

Este PR implementa el manejo de apagado graceful (SIGTERM y SIGINT) en el servidor para desmarcar los personajes conectados en la base de datos antes de finalizar el proceso, evitando que queden bloqueados tras un reinicio o deploy.

Cambios realizados

  1. Handler de SIGTERM y SIGINT conectado a gracefulShutdown.
  2. Notificación previa a clientes conectados vía handleProtocol.consoleToAll.
  3. Llamada al endpoint POST /internal/characters/reset-connected para desmarcar personajes activos en la DB.
  4. Timeout de seguridad de 5 segundos para forzar salida limpia si la API no responde.
  5. Cierre ordenado de servidores WebSocket y HTTP.
  6. Se mantiene el reset al arrancar como red de seguridad adicional.

Bounty Payout Addresses

  • LTC: LPnftYop8yhRNQZstysT3vuJf3XkpQWKTC
  • EVM (Base/ETH): 0x32BB3df5B74a594956a0f33Bc353511Fa759FCa4
  • Solana (SOL): 8Xo39uq9LoaM2rQEkgaaSfuThqHZTd18yGdJSXffkLwM
  • BTC: bc1qpyu6866qcgt26sqw4dn2mlmp8d0yc657fuedkv
  • DOGE: DDMU6D9TCE3BhqqYyy7MUZQD7JhfL39FpE

Comment thread server/src/server.ts
Comment thread server/src/server.ts Outdated
@trexfr-ops

trexfr-ops commented Aug 19, 2026

Copy link
Copy Markdown
Author

Updated commit pushed:

  • Restored the FLOOR_ITEM_SWEEP_CHECK_MS scheduler callback.
  • Wrapped wsServer.close() and httpServer.close() in Promise.all to await callback completion before exiting.

@gitar-bot

gitar-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Adds graceful shutdown handlers for SIGTERM and SIGINT to reset connected characters and close servers cleanly, addressing the broken createDynamicScheduler syntax error and premature process exit issues.

✅ 2 resolved
Bug: Broken createDynamicScheduler call — syntax error, sweep removed

📄 server/src/server.ts:944-946
The diff accidentally deleted the callback argument and closing ); of the floor-item-sweep scheduler, leaving createDynamicScheduler(() => FLOOR_ITEM_SWEEP_CHECK_MS, followed by void saveOnlineStatsSnapshot(); inside the still-open argument list. This is a syntax error (semicolon inside the call arguments, unterminated call) so the file will fail to compile/run entirely, and the floor-item sweep tick is no longer scheduled. Restore the original scheduler and place saveOnlineStatsSnapshot() after it.

Bug: process.exit(0) fires before wsServer/httpServer.close() completes

📄 server/src/server.ts:994-1004
wsServer.close() and httpServer.close() complete asynchronously via callbacks, but process.exit(0) runs synchronously in the finally block immediately after invoking them. The process terminates before in-flight connections are drained, so the "ordered shutdown" of step 3 does not actually happen. Await the close callbacks (e.g. wrap each in a Promise) before exiting, then clear the force-exit timeout.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

El server no desmarca personajes al apagarse: quedan bloqueados tras un reinicio

1 participant