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:
22
src/index.ts
22
src/index.ts
@@ -873,8 +873,8 @@ if (cluster.isPrimary) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// ── Worker: cada uno tiene su propio McpServer singleton ──
|
// ── 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)
|
// Sin mutex: cada request se atiende concurrentemente dentro del worker.
|
||||||
let workerBusy: Promise<void> = Promise.resolve();
|
// StreamableHTTPServerTransport es stateless (uno por request), sin estado compartido.
|
||||||
|
|
||||||
async function handleMcpRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
async function handleMcpRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
||||||
const transport = new StreamableHTTPServerTransport({
|
const transport = new StreamableHTTPServerTransport({
|
||||||
@@ -893,16 +893,14 @@ if (cluster.isPrimary) {
|
|||||||
res.writeHead(404).end("Not found");
|
res.writeHead(404).end("Not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
workerBusy = workerBusy
|
handleMcpRequest(req, res).catch((err) => {
|
||||||
.then(() => handleMcpRequest(req, res))
|
console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err);
|
||||||
.catch((err) => {
|
if (!res.headersSent) {
|
||||||
console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err);
|
res.writeHead(500, { "Content-Type": "application/json" }).end(
|
||||||
if (!res.headersSent) {
|
JSON.stringify({ jsonrpc: "2.0", error: { code: -32603, message: String(err) }, id: null })
|
||||||
res.writeHead(500, { "Content-Type": "application/json" }).end(
|
);
|
||||||
JSON.stringify({ jsonrpc: "2.0", error: { code: -32603, message: String(err) }, id: null })
|
}
|
||||||
);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.listen(8080, () => {
|
httpServer.listen(8080, () => {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export async function updatePageContentRealtime(
|
|||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
if (provider) provider.destroy();
|
if (provider) provider.destroy();
|
||||||
reject(new Error("Connection timeout to collaboration server"));
|
reject(new Error("Connection timeout to collaboration server"));
|
||||||
}, 25000);
|
}, 120000);
|
||||||
|
|
||||||
const provider = new HocuspocusProvider({
|
const provider = new HocuspocusProvider({
|
||||||
url: wsUrl,
|
url: wsUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user