fix: harden signal handlers with robust container detection (Issue #277)

Production-ready improvements based on comprehensive code review:

Critical Fixes:
- Robust container detection: Checks multiple env vars (IS_DOCKER, IS_CONTAINER)
  with flexible formats (true/1/yes) and filesystem markers (/.dockerenv,
  /run/.containerenv) for Docker, Kubernetes, Podman, containerd support
- Fixed redundant exit calls: Removed immediate exit, use 1000ms timeout for
  graceful shutdown allowing cleanup to complete
- Added error handling for stdin registration with try-catch
- Added shutdown trigger logging (SIGTERM/SIGINT/SIGHUP/STDIN_END/STDIN_CLOSE)

Improvements:
- Increased timeout from 500ms to 1000ms for slower systems
- Added null safety for stdin operations
- Enhanced documentation explaining behavior in different environments
- More descriptive variable names (isDocker → isContainer)

Testing:
- Supports Docker, Kubernetes, Podman, and other container runtimes
- Graceful fallback if container detection fails
- Works in Claude Desktop, containers, and manual execution

Code Review: Approved by code-reviewer agent
All critical and warning issues addressed

Reported by: @Eddy-Chahed
Issue: #277

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-10-06 11:55:26 +02:00
parent 08abdb7937
commit b12a927a10
3 changed files with 120 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "n8n-mcp",
"version": "2.16.0",
"version": "2.16.1",
"description": "Integration between n8n workflow automation and Model Context Protocol (MCP)",
"main": "dist/index.js",
"bin": {