Skip to content

Commit e32454d

Browse files
committed
fix: prevent server shutdown on uncaught errors
CRITICAL FIX: Uncaught exceptions and unhandled promise rejections no longer kill the entire server. This was causing catastrophic failures where a single tool error would shut down the server. Changes: - uncaughtException handler: LOG only, do not call gracefulShutdown() - unhandledRejection handler: LOG only, do not call gracefulShutdown() - Added comments explaining that tool errors are already caught - Version bump to 1.2.3 WHY THIS IS CRITICAL: A production server should NEVER crash because of a single tool error. Tool errors are caught in the try/catch at line 208, but if any promise rejection escapes that catch, the old code would kill the entire server and all active sessions. NOW: - Server logs the error and continues running - Only SIGTERM/SIGINT trigger graceful shutdown - Individual tool errors return error responses, not crash the server This is essential for production stability.
1 parent 6a0bf16 commit e32454d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tsdav-mcp-server",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Model Context Protocol (MCP) server for CalDAV/CardDAV/VTODO integration via tsdav - enables AI systems to manage calendars, contacts, and tasks",
55
"type": "module",
66
"main": "src/index.js",

src/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,17 @@ async function gracefulShutdown(signal) {
426426
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
427427
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
428428

429-
// Handle uncaught errors
429+
// Handle uncaught errors - LOG but DO NOT kill the server
430+
// Tool errors are caught in the tool handler try/catch (line 208)
431+
// These handlers are only for truly unexpected errors that escape our error handling
430432
process.on('uncaughtException', (error) => {
431-
logger.error({ error: error.message, stack: error.stack }, 'Uncaught exception');
432-
gracefulShutdown('uncaughtException');
433+
logger.error({ error: error.message, stack: error.stack }, 'Uncaught exception - server continuing');
434+
// DO NOT call gracefulShutdown() - let the server continue running
433435
});
434436

435437
process.on('unhandledRejection', (reason, promise) => {
436-
logger.error({ reason, promise }, 'Unhandled promise rejection');
437-
gracefulShutdown('unhandledRejection');
438+
logger.error({ reason, promise }, 'Unhandled promise rejection - server continuing');
439+
// DO NOT call gracefulShutdown() - let the server continue running
438440
});
439441

440442
let server;

0 commit comments

Comments
 (0)