maxpool 1.24.78 → 1.24.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +39 -10
- package/src/reload-protocol.js +1 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
RELOAD_SWAPPED, RELOAD_ROLLED_BACK,
|
|
52
52
|
MSG_LISTEN, MSG_RELEASE, MSG_TAKEOVER, MSG_PROBE_READY,
|
|
53
53
|
MSG_RELOAD_REQUEST, MSG_READY, MSG_FAILED, MSG_RELEASED, MSG_PRIMARY, MSG_ROLLED_BACK,
|
|
54
|
-
MSG_TTY_REASSERT,
|
|
54
|
+
MSG_TTY_REASSERT, MSG_CONN,
|
|
55
55
|
} from './reload-protocol.js';
|
|
56
56
|
|
|
57
57
|
const args = process.argv.slice(2);
|
|
@@ -222,12 +222,25 @@ async function supervisorCommand() {
|
|
|
222
222
|
|
|
223
223
|
// Bind once. EADDRINUSE / EACCES here is a cold-start failure → exit(1) is
|
|
224
224
|
// correct (there's no worker to keep alive yet).
|
|
225
|
-
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
// supervisor's
|
|
229
|
-
//
|
|
230
|
-
//
|
|
225
|
+
// pauseOnConnect: a socket the supervisor accepts must reach the worker with every
|
|
226
|
+
// byte still unread, so the supervisor never consumes the request it is relaying.
|
|
227
|
+
let masterServer = createServer({ pauseOnConnect: true });
|
|
228
|
+
// The supervisor's accept loop is LIVE from bind until a worker confirms it is the
|
|
229
|
+
// sole acceptor (MSG_PRIMARY), and again over the reload cutover gap. It shares the
|
|
230
|
+
// listening socket with the worker, so it WINS some accepts. A connection accepted
|
|
231
|
+
// here used to be left dangling (this server had no 'connection' handler): the client
|
|
232
|
+
// hung, then got ECONNRESET, and the request never reached any worker (the flaky
|
|
233
|
+
// reload-oauth-refresh test, 2026-11-08). Hand every such socket to the worker that
|
|
234
|
+
// is serving, or about to: `acceptTarget` (the incoming worker during a reload) else
|
|
235
|
+
// the active one. No live worker → close it so the client retries now, never hangs.
|
|
236
|
+
let acceptTarget = null;
|
|
237
|
+
masterServer.on('connection', sock => {
|
|
238
|
+
const target = acceptTarget || activeWorker;
|
|
239
|
+
if (!target || !target.child.connected) { sock.destroy(); return; }
|
|
240
|
+
try {
|
|
241
|
+
target.child.send({ type: MSG_CONN }, sock, err => { if (err) sock.destroy(); });
|
|
242
|
+
} catch { sock.destroy(); }
|
|
243
|
+
});
|
|
231
244
|
const relistenMaster = (retriesOnBusy = 20) => new Promise((resolve, reject) => {
|
|
232
245
|
if (masterServer.listening) { resolve(); return; }
|
|
233
246
|
const onListen = () => { masterServer.removeListener('error', onErr); resolve(); };
|
|
@@ -246,6 +259,14 @@ async function supervisorCommand() {
|
|
|
246
259
|
masterServer.once('listening', onListen);
|
|
247
260
|
masterServer.listen(port, host);
|
|
248
261
|
});
|
|
262
|
+
// What goes over IPC to a worker: the RAW listening handle, not the net.Server wrapper.
|
|
263
|
+
// Sent as a net.Server, Node builds an intermediate net.Server in the worker that
|
|
264
|
+
// listen()s on it and ACCEPTS whatever is already queued before user code can attach
|
|
265
|
+
// a listener (measured: with 8 connections queued, the worker's HTTP server got 0-5
|
|
266
|
+
// and the rest sat unread in that intermediate server, black-holed). The raw handle
|
|
267
|
+
// has no such wrapper: the worker's http.Server listen()s on it directly.
|
|
268
|
+
// Falls back to the wrapper if a future Node hides the handle (old behaviour).
|
|
269
|
+
const masterHandle = () => masterServer._handle || masterServer;
|
|
249
270
|
const closeMasterAccept = () => new Promise(resolve => {
|
|
250
271
|
if (!masterServer.listening) { resolve(); return; }
|
|
251
272
|
masterServer.close(() => resolve());
|
|
@@ -327,7 +348,7 @@ async function supervisorCommand() {
|
|
|
327
348
|
const worker = makeWorkerChannel(child);
|
|
328
349
|
if (!reload) {
|
|
329
350
|
// Cold start: hand the socket and tell it to go primary immediately.
|
|
330
|
-
worker.send({ type: MSG_LISTEN },
|
|
351
|
+
worker.send({ type: MSG_LISTEN }, masterHandle());
|
|
331
352
|
}
|
|
332
353
|
return worker;
|
|
333
354
|
};
|
|
@@ -373,11 +394,13 @@ async function supervisorCommand() {
|
|
|
373
394
|
const outcome = await runReloadBaton({
|
|
374
395
|
oldWorker,
|
|
375
396
|
newWorker,
|
|
376
|
-
handle:
|
|
397
|
+
handle: masterHandle(),
|
|
377
398
|
// After the OLD worker has released its fd, re-arm the supervisor's own
|
|
378
399
|
// listener to cover the cutover gap, then hand THAT live handle to the
|
|
379
400
|
// new worker. The new worker's MSG_PRIMARY then closes it again.
|
|
380
|
-
|
|
401
|
+
// The old worker has released, so gap-accepted connections now belong to the
|
|
402
|
+
// incoming worker (before this point the still-serving old one is the target).
|
|
403
|
+
prepareHandle: async () => { acceptTarget = newWorker; await relistenMaster(); return masterHandle(); },
|
|
381
404
|
// Generous, env-tunable readiness/takeover budgets — the 10s default rolled back
|
|
382
405
|
// on this user's loaded Mac (the update never landed). See RELOAD_READY_MS.
|
|
383
406
|
readyTimeoutMs: RELOAD_READY_MS,
|
|
@@ -427,6 +450,7 @@ async function supervisorCommand() {
|
|
|
427
450
|
activeWorker = null;
|
|
428
451
|
endTurn?.({ code: null, signal: 'SIGKILL', fallback: true });
|
|
429
452
|
} finally {
|
|
453
|
+
acceptTarget = null;
|
|
430
454
|
reloadInFlight = false;
|
|
431
455
|
}
|
|
432
456
|
};
|
|
@@ -1564,6 +1588,11 @@ async function serverWorkerCommand() {
|
|
|
1564
1588
|
// never sit alive-but-not-primary (the blank-screen `r`-restart hang).
|
|
1565
1589
|
console.error('[Maxpool] Cold worker received MSG_LISTEN with no socket handle — exiting for respawn.');
|
|
1566
1590
|
process.exit(SERVER_RESTART_EXIT_CODE);
|
|
1591
|
+
} else if (msg?.type === MSG_CONN) {
|
|
1592
|
+
// A connection the supervisor's own accept loop won the race for (cold start
|
|
1593
|
+
// before MSG_PRIMARY, or the reload cutover gap). Serve it exactly as if we
|
|
1594
|
+
// had accepted it: http.Server wires up on the 'connection' event.
|
|
1595
|
+
if (handle) { handle.resume?.(); server.emit('connection', handle); }
|
|
1567
1596
|
} else if (msg?.type === MSG_PROBE_READY) {
|
|
1568
1597
|
// Headless reload worker: we've booted the new code and restored quota
|
|
1569
1598
|
// in memory. Confirm readiness (we are NOT yet accepting / writing).
|
package/src/reload-protocol.js
CHANGED
|
@@ -30,6 +30,7 @@ export const MSG_FAILED = 'failed'; // worker failed to boot/bind/restore
|
|
|
30
30
|
export const MSG_RELEASED = 'released'; // old worker stopped accepting + writing, flushed
|
|
31
31
|
export const MSG_PRIMARY = 'primary'; // new worker is now sole acceptor + lease holder
|
|
32
32
|
export const MSG_QUOTA_STATE = 'quota-state'; // old worker hands its in-memory quota to supervisor
|
|
33
|
+
export const MSG_CONN = 'conn'; // (with socket) supervisor-accepted connection handed to a worker to serve
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Outcome codes for a reload attempt, surfaced to the supervisor so it can log
|