Compare commits

...

2 Commits

Author SHA1 Message Date
e7cf1fa022 fix: remove worker mutex and increase collab timeout to 120s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 13m36s
2026-06-01 14:27:18 -06:00
8a533d028d 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>
2026-06-01 20:24:19 +00:00
2 changed files with 11 additions and 13 deletions

View File

@@ -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,9 +893,7 @@ 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))
.catch((err) => {
console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err); console.error(`[docmost-mcp] Worker PID=${process.pid} error:`, err);
if (!res.headersSent) { if (!res.headersSent) {
res.writeHead(500, { "Content-Type": "application/json" }).end( res.writeHead(500, { "Content-Type": "application/json" }).end(

View File

@@ -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,