Add process monitoring and graceful shutdown handlers - #216
Merged
Merged
Conversation
Ported from specref (#965): - lib/logger.js: memory() gives a snapshot of process.memoryUsage() in MB, and installProcessHandlers() logs uncaught exceptions, unhandled rejections, process warnings, SIGTERM/SIGINT/SIGHUP (closing the server first) and the process exit, with the memory usage where it helps. - index.js: memory usage on startup, a "memory usage" line every minute, and a fatal line on a server error. - lib/app.js: at debug level, a "request received" line with the memory usage, skipping /health and loopback requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAkjjVdTENcYvZSiGWWVA
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.
Summary
This PR adds comprehensive process monitoring and graceful shutdown capabilities to the application, including memory usage tracking, process event handlers, and improved logging for debugging production issues.
Key Changes
memory()function to capture process memory usage (RSS, heap, external, array buffers) in MB for inclusion in log linesinstallProcessHandlers()to catch and log uncaught exceptions, unhandled promise rejections, process warnings, and shutdown signals (SIGTERM, SIGINT, SIGHUP)Implementation Details
/healthendpoint are excluded from request logging to reduce log noiseunref()on intervals to prevent them from keeping the process alivehttps://claude.ai/code/session_01CnAkjjVdTENcYvZSiGWWVA