Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

Story

MCP Server Shutdown Tests Expose Timeout and Connection Pitfalls

AI summary

The author tested an Express-based MCP Server running an eight-second slow_task during deployment shutdowns. After the server received SIGTERM two seconds into the task, one client waited 58 seconds for an already-dead connection before reporting an MCP timeout, while server.close() preserved active requests but waited for connections rather than task completion. A tested shutdown sequence marked the server unhealthy, stopped accepting traffic, waited for tracked in-flight tasks, and actively closed remaining connections.

In-depth insight

The measurements show why containerized MCP Servers with long-running tools need explicit task tracking, draining, bounded grace periods, and active connection cleanup rather than relying on server.close() alone.

我模拟了一次发版:一个 8 秒的任务跑到第 2 秒,服务端收到 SIGTERM。

然后我盯着客户端,等它告诉我出事了。

它等了 58 秒,报了一句"请求超时"。

那一刻我意识到,服务端早就没了,客户端却还在等。等到它自己的超时用尽,才给出一个"超时"——而这个错误会让人以为"服务只是慢",于是重试,于是又打到另一个正在被杀的实例。

这篇把发版那一刻的事从头跑了一遍:三种关闭方式,同一个 8 秒的任务,看客户端到底收到什么。

结论先放这儿:server.close() 不是"等我一下",是"等连接关";而客户端分不清"服务死了"和"服务慢了"。

#Model Context Protocol#Express#Node.js#Kubernetes

Original · 12 min readRead the original
Group chat

No comments yet. Start the conversation.