Performance improvements: fix MCP server shutdown and disable caching

- Add proper shutdown handling for MCP servers
  - Listen for stdin EOF (main issue causing 6min delays)
  - Add transport.close() to properly close connections
  - Add 5-minute timeout safety net
  - Handle SIGHUP signal
- Disable Bun caching to avoid timeout errors
- Add Dockerfile.runner for pre-built container option
- Create optimized workflow example without container layer
This commit is contained in:
claude
2025-07-30 06:59:23 +00:00
parent 2972a854d4
commit 7944008493
4 changed files with 81 additions and 20 deletions

View File

@@ -1267,21 +1267,38 @@ async function runServer() {
console.log(`[GITEA-MCP] Connecting to transport...`);
await server.connect(transport);
console.log(`[GITEA-MCP] Gitea MCP server connected and ready!`);
// Handle server shutdown
const shutdown = async () => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Shutting down server...`);
try {
await server.close();
transport.close();
} catch (error) {
console.error(`[GITEA-MCP] Error during shutdown:`, error);
}
process.exit(0);
};
process.on("exit", () => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Server shutting down...`);
server.close();
console.log(`[GITEA-MCP ${new Date().toISOString()}] Server exiting...`);
});
// Add more signal handlers for debugging
process.on("SIGTERM", () => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Received SIGTERM signal`);
process.exit(0);
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);
process.on("SIGHUP", shutdown);
// Also listen for stdin close (EOF)
process.stdin.on("end", () => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Stdin closed, shutting down...`);
shutdown();
});
process.on("SIGINT", () => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Received SIGINT signal`);
process.exit(0);
});
// Add timeout safety net (5 minutes)
setTimeout(() => {
console.log(`[GITEA-MCP ${new Date().toISOString()}] Timeout reached, forcing shutdown...`);
shutdown();
}, 5 * 60 * 1000);
}
console.log(`[GITEA-MCP] Calling runServer()...`);

View File

@@ -496,21 +496,38 @@ async function runServer() {
console.log(`[LOCAL-GIT-MCP] Connecting to transport...`);
await server.connect(transport);
console.log(`[LOCAL-GIT-MCP] MCP server connected and ready!`);
// Handle server shutdown
const shutdown = async () => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Shutting down server...`);
try {
await server.close();
transport.close();
} catch (error) {
console.error(`[LOCAL-GIT-MCP] Error during shutdown:`, error);
}
process.exit(0);
};
process.on("exit", () => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Server shutting down...`);
server.close();
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Server exiting...`);
});
// Add more signal handlers for debugging
process.on("SIGTERM", () => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Received SIGTERM signal`);
process.exit(0);
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);
process.on("SIGHUP", shutdown);
// Also listen for stdin close (EOF)
process.stdin.on("end", () => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Stdin closed, shutting down...`);
shutdown();
});
process.on("SIGINT", () => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Received SIGINT signal`);
process.exit(0);
});
// Add timeout safety net (5 minutes)
setTimeout(() => {
console.log(`[LOCAL-GIT-MCP ${new Date().toISOString()}] Timeout reached, forcing shutdown...`);
shutdown();
}, 5 * 60 * 1000);
}
console.log(`[LOCAL-GIT-MCP] Calling runServer()...`);