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:
26
Dockerfile.runner
Normal file
26
Dockerfile.runner
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM node:18-slim
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
curl \
|
||||
unzip \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Bun globally
|
||||
RUN curl -fsSL https://bun.sh/install | bash && \
|
||||
ln -s /root/.bun/bin/bun /usr/local/bin/bun
|
||||
|
||||
# Pre-install Claude Code and dependencies
|
||||
WORKDIR /opt/claude-action
|
||||
COPY package.json bun.lockb* ./
|
||||
RUN bun install --frozen-lockfile
|
||||
|
||||
# Install claude-code globally
|
||||
RUN bun add -g @anthropic-ai/claude-code@1.0.62
|
||||
|
||||
# Set up environment
|
||||
ENV PATH="/root/.bun/bin:${PATH}"
|
||||
|
||||
WORKDIR /workspace
|
||||
@@ -84,6 +84,7 @@ runs:
|
||||
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # https://github.com/oven-sh/setup-bun/releases/tag/v2.0.2
|
||||
with:
|
||||
bun-version: 1.2.11
|
||||
cache: false
|
||||
|
||||
- name: Install Dependencies
|
||||
shell: bash
|
||||
|
||||
@@ -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()...`);
|
||||
|
||||
@@ -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()...`);
|
||||
|
||||
Reference in New Issue
Block a user