Skip to content

🐛 fix: improve graceful shutdown handling - #2

Open
sliver2er wants to merge 3 commits into
kubony:masterfrom
sliver2er:fix/graceful-shutdown
Open

🐛 fix: improve graceful shutdown handling#2
sliver2er wants to merge 3 commits into
kubony:masterfrom
sliver2er:fix/graceful-shutdown

Conversation

@sliver2er

Copy link
Copy Markdown

Changes

  • Track SSE clients: All SSE connections are now tracked in a Set
  • Broadcast shutdown event: Before closing the server, all SSE clients receive a 'shutdown' event
  • Destroy active sockets: Active HTTP connections are destroyed on shutdown to prevent server hanging
  • Prevent duplicate shutdown: Added isShuttingDown flag to prevent multiple shutdown calls from Ctrl+C presses
  • Immediate termination: Server now closes immediately on first Ctrl+C instead of requiring multiple presses

Problem

Previously, the server would hang on shutdown because:

  1. SSE (Server-Sent Events) connections remained open indefinitely
  2. server.close() would wait for all connections to close before triggering the callback
  3. This callback never fired, so the process never exited
  4. Users had to press Ctrl+C multiple times to force shutdown

Solution

  1. Track all SSE client connections in a Set
  2. When SIGINT/SIGTERM is received, broadcast a 'shutdown' event to all SSE clients
  3. Immediately close all SSE connections
  4. Destroy any remaining HTTP sockets
  5. Call process.exit() after closing the server
  6. Use isShuttingDown flag to prevent duplicate shutdown handlers

Testing

npm run build
npx viewcc
# Press Ctrl+C once - server should shut down immediately
# No longer requires multiple Ctrl+C presses

- build:webapp 스크립트에 npm install 추가
- webapp node_modules 미설치 시 빌드 실패하는 문제 해결
- README 로컬 개발 가이드 문구 명확화
- minimatch 9.0.5 -> 9.0.9
- qs 6.14.1 -> 6.14.2
- 패키지명 claude-viz -> viewcc 반영
- Track SSE clients and broadcast shutdown event before closing
- Destroy active sockets on shutdown to prevent hanging
- Add isShuttingDown flag to prevent duplicate shutdown calls
- Server now closes immediately on Ctrl+C instead of requiring multiple presses
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.

1 participant