test(ci): backport concurrent MCP expiry fixture fix (#155577)

This commit is contained in:
Dallin Romney 2026-09-22 01:23:49 -07:00 • committed by GitHub
parent 724261e7ff
commit 4cb5411237
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 8 deletions

View file

@ -305,6 +305,7 @@ async function runHttp() {
}
const app = createMcpExpressApp();
const sessions = new Map();
const pendingSessionExpirations = new Map();
const records = new Set();
const catalogState = { rotated: false, expiryCalls: 0 };
const appFixtureEnabled = process.env.MCP_APP_GRANT_REVALIDATION_FIXTURE === "1";
@ -353,14 +354,26 @@ async function runHttp() {
const sessionId = req.headers["mcp-session-id"];
let transport;
if (typeof sessionId === "string") {
if (req.body?.params?.arguments?.marker === "expire-session") {
const marker = req.body?.params?.arguments?.marker;
if (marker === "expire-session" || marker === "expire-concurrent-session") {
catalogState.expiryCalls += 1;
const pending = pendingSessionExpirations.get(sessionId) ?? [];
pending.push({ response: res, id: req.body?.id ?? null });
if (marker === "expire-concurrent-session" && pending.length < 2) {
// Expire only after both calls reach this session. The first 404
// otherwise retires the transport before the second request arrives.
pendingSessionExpirations.set(sessionId, pending);
return;
}
pendingSessionExpirations.delete(sessionId);
sessions.delete(sessionId);
res.status(404).json({
jsonrpc: "2.0",
error: { code: -32001, message: "Session not found" },
id: req.body?.id ?? null,
});
for (const { response, id } of pending) {
response.status(404).json({
jsonrpc: "2.0",
error: { code: -32001, message: "Session not found" },
id,
});
}
return;
}
const record = sessions.get(sessionId);

View file

@ -285,18 +285,19 @@ describe("Gateway/node MCP real-process stress", () => {
descriptors = (await waitForNode(gateway, nodeId, 3)).nodePluginTools ?? [];
const streamable = descriptorFor(descriptors, "streamableHttp");
// The fixture admits both HTTP requests before expiring their shared session.
const expired = await Promise.allSettled([
invokeNodeMcpPayload({
gateway,
nodeId,
descriptor: streamable,
marker: "expire-session",
marker: "expire-concurrent-session",
}),
invokeNodeMcpPayload({
gateway,
nodeId,
descriptor: streamable,
marker: "expire-session",
marker: "expire-concurrent-session",
}),
]);
expect(expired.every((result) => result.status === "rejected")).toBe(true);