fix: remove worker mutex and increase collab timeout to 120s

- Remove workerBusy promise chain (mutex) in src/index.ts: each
  StreamableHTTPServerTransport is stateless and per-request, so
  concurrent handling within a worker is safe. Eliminates request
  starvation when long page writes are in flight.
- Raise the Hocuspocus safety timeout in collaboration.ts from 25 s
  to 120 s, giving large documents enough time to complete the Yjs
  sync phase before the hard abort fires.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 20:24:19 +00:00
parent a089a92205
commit 8a533d028d
2 changed files with 11 additions and 13 deletions

View File

@@ -873,8 +873,8 @@ if (cluster.isPrimary) {
});
} else {
// ── Worker: cada uno tiene su propio McpServer singleton ──
// El mutex serializa las requests dentro de este worker (stateless, 1 request a la vez por worker)
let workerBusy: Promise<void> = Promise.resolve();
// Sin mutex: cada request se atiende concurrentemente dentro del worker.
// StreamableHTTPServerTransport es stateless (uno por request), sin estado compartido.
async function handleMcpRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
const transport = new StreamableHTTPServerTransport({
@@ -893,16 +893,14 @@ if (cluster.isPrimary) {
res.writeHead(404).end("Not found");
return;
}
workerBusy = workerBusy
.then(() => handleMcpRequest(req, res))
.catch((err) => {
console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err);
if (!res.headersSent) {
res.writeHead(500, { "Content-Type": "application/json" }).end(
JSON.stringify({ jsonrpc: "2.0", error: { code: -32603, message: String(err) }, id: null })
);
}
});
handleMcpRequest(req, res).catch((err) => {
console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err);
if (!res.headersSent) {
res.writeHead(500, { "Content-Type": "application/json" }).end(
JSON.stringify({ jsonrpc: "2.0", error: { code: -32603, message: String(err) }, id: null })
);
}
});
});
httpServer.listen(8080, () => {

View File

@@ -67,7 +67,7 @@ export async function updatePageContentRealtime(
const timer = setTimeout(() => {
if (provider) provider.destroy();
reject(new Error("Connection timeout to collaboration server"));
}, 25000);
}, 120000);
const provider = new HocuspocusProvider({
url: wsUrl,