opentray 0.33.0 → 0.33.2
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/dist/index.d.mts +53 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +111 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -209,8 +209,8 @@ interface TrayHandle {
|
|
|
209
209
|
setTooltip(tooltip: Tooltip$1): Promise<void>;
|
|
210
210
|
setIcon(icon: Icon$1): Promise<void>;
|
|
211
211
|
loadExtension(options: ExtensionLoadOptions): Promise<void>;
|
|
212
|
-
commandExtension(ext: string, data: unknown): Promise<void>;
|
|
213
|
-
requestExtension<TValue = unknown>(ext: string, data: unknown): Promise<ExtensionRequestResult<TValue>>;
|
|
212
|
+
commandExtension(ext: string, data: unknown, callOptions?: TransportRequestOptions): Promise<void>;
|
|
213
|
+
requestExtension<TValue = unknown>(ext: string, data: unknown, callOptions?: TransportRequestOptions): Promise<ExtensionRequestResult<TValue>>;
|
|
214
214
|
extend<TCapability extends object, TOptions = undefined>(extension: TrayExtension<TCapability, TOptions>, options?: TOptions): TrayHandle & TCapability;
|
|
215
215
|
destroy(): Promise<void>;
|
|
216
216
|
}
|
|
@@ -289,8 +289,8 @@ interface TrayExtensionContext {
|
|
|
289
289
|
readonly artifact: NativeExtensionArtifact;
|
|
290
290
|
readonly mountId: string;
|
|
291
291
|
ensureLoaded(): Promise<void>;
|
|
292
|
-
command(data: unknown): Promise<void>;
|
|
293
|
-
request<TValue = unknown>(data: unknown): Promise<ExtensionRequestResult<TValue>>;
|
|
292
|
+
command(data: unknown, callOptions?: TransportRequestOptions): Promise<void>;
|
|
293
|
+
request<TValue = unknown>(data: unknown, callOptions?: TransportRequestOptions): Promise<ExtensionRequestResult<TValue>>;
|
|
294
294
|
}
|
|
295
295
|
interface TrayExtension<TCapability extends object, TOptions = undefined> {
|
|
296
296
|
readonly name: string;
|
|
@@ -429,6 +429,12 @@ interface TransportRecoveryOptions {
|
|
|
429
429
|
backoffFactor?: number;
|
|
430
430
|
/** Backoff ceiling in milliseconds (default 30_000). */
|
|
431
431
|
backoffCapMs?: number;
|
|
432
|
+
/**
|
|
433
|
+
* Budget for one reconnect attempt (default 10 s). A connect factory that
|
|
434
|
+
* never settles counts as a failed attempt instead of parking the
|
|
435
|
+
* recovery loop; its late-resolving connection is closed on arrival.
|
|
436
|
+
*/
|
|
437
|
+
connectTimeoutMs?: number;
|
|
432
438
|
/**
|
|
433
439
|
* Tier 2 hand-over (default: absent). When provided, an uninvited death
|
|
434
440
|
* performs a bounded teardown, invokes this callback exactly once, and goes
|
|
@@ -473,6 +479,7 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
473
479
|
private readonly cooldownMs;
|
|
474
480
|
private readonly backoffFactor;
|
|
475
481
|
private readonly backoffCapMs;
|
|
482
|
+
private readonly connectTimeoutMs;
|
|
476
483
|
private readonly restartApp;
|
|
477
484
|
private connection;
|
|
478
485
|
private generation;
|
|
@@ -485,10 +492,18 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
485
492
|
private unwireGeneration;
|
|
486
493
|
private heartbeatTimer;
|
|
487
494
|
private heartbeatOrdinal;
|
|
495
|
+
private heartbeatInFlight;
|
|
488
496
|
private consecutiveHeartbeatFailures;
|
|
489
497
|
private lastSettledAt;
|
|
490
498
|
private restartTimestamps;
|
|
491
499
|
private callerInitiated;
|
|
500
|
+
/**
|
|
501
|
+
* Monotonic teardown epoch: `shutdown()` bumps it so an in-flight recovery
|
|
502
|
+
* attempt can detect that it raced caller-initiated teardown and abort
|
|
503
|
+
* instead of resurrecting a destroyed runtime (no candidate adoption, no
|
|
504
|
+
* `healthy` transition, no restarted heartbeat).
|
|
505
|
+
*/
|
|
506
|
+
private teardownEpoch;
|
|
492
507
|
private shutdownPromise;
|
|
493
508
|
constructor(connectFactory: () => Promise<LocalBrokerClient>, options: CreateTransportSupervisorOptions);
|
|
494
509
|
/** Current supervision state; edge events go to {@link onTransportStateChange}. */
|
|
@@ -550,8 +565,11 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
550
565
|
/**
|
|
551
566
|
* Graceful teardown channel (W4/W3): idempotent, marks the supervision
|
|
552
567
|
* caller-initiated synchronously (so the close-driven death event can
|
|
553
|
-
* never trigger recovery),
|
|
554
|
-
*
|
|
568
|
+
* never trigger recovery), bumps the teardown epoch (so an in-flight
|
|
569
|
+
* recovery attempt aborts instead of resurrecting the runtime), stops the
|
|
570
|
+
* heartbeat, then closes the current generation — including an
|
|
571
|
+
* adoption-in-progress candidate routed through `this.connection` —
|
|
572
|
+
* within its bounded graceful-close budget.
|
|
555
573
|
*/
|
|
556
574
|
shutdown(): Promise<void>;
|
|
557
575
|
/** LocalBrokerClient structural compatibility: graceful close == shutdown. */
|
|
@@ -563,6 +581,10 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
563
581
|
* proves its own liveness, so the probe budget is spent only on silence.
|
|
564
582
|
* A probe failure of any rejection class (typed timeout, transport-lost,
|
|
565
583
|
* broker error frame) counts; a successful settlement resets the streak.
|
|
584
|
+
* Single-flight with a generation token: at most one probe per generation
|
|
585
|
+
* is outstanding (a configured interval shorter than the probe deadline
|
|
586
|
+
* must not run concurrent probes whose completions double-count), and a
|
|
587
|
+
* probe that outlives its generation settles nothing.
|
|
566
588
|
*/
|
|
567
589
|
private heartbeatTick;
|
|
568
590
|
private noteSuccessfulSettlement;
|
|
@@ -591,9 +613,18 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
591
613
|
* original connect options → journal replay → facade rebuilds → healthy.
|
|
592
614
|
* Every attempt consumes budget up front; a failed attempt (connect,
|
|
593
615
|
* replay, or rebuild — including artifact identity mismatches) retries
|
|
594
|
-
* inside the remaining budget until exhaustion abandons the runtime.
|
|
616
|
+
* inside the remaining budget until exhaustion abandons the runtime. Each
|
|
617
|
+
* reconnect attempt is bounded by the connect budget, and every step
|
|
618
|
+
* re-checks the teardown epoch so a shutdown racing the loop aborts it
|
|
619
|
+
* instead of resurrecting the runtime.
|
|
595
620
|
*/
|
|
596
621
|
private runRecovery;
|
|
622
|
+
/**
|
|
623
|
+
* One reconnect attempt under the connect budget. A factory that never
|
|
624
|
+
* settles counts as a failed attempt; a connection arriving after the
|
|
625
|
+
* budget expired is closed on arrival so no orphan generation leaks.
|
|
626
|
+
*/
|
|
627
|
+
private connectWithBudget;
|
|
597
628
|
private cooldownForBackoff;
|
|
598
629
|
/**
|
|
599
630
|
* Sliding-window budget: one timestamp per respawn attempt (successful or
|
|
@@ -603,13 +634,23 @@ declare class SupervisedLocalBrokerConnection {
|
|
|
603
634
|
private consumeRestartBudget;
|
|
604
635
|
/**
|
|
605
636
|
* Wires the candidate generation, replays the journal, and runs the
|
|
606
|
-
* facade rebuild callbacks. `this.connection`
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
637
|
+
* facade rebuild callbacks. The candidate becomes `this.connection` for
|
|
638
|
+
* the adoption's duration — facade rebuild callbacks route their
|
|
639
|
+
* re-creation commands through this supervisor, so they must reach the
|
|
640
|
+
* candidate, not the dead generation (the rebuild-routing law). A failure
|
|
641
|
+
* rolls the candidate back out (unwired, closed) and restores the dead
|
|
642
|
+
* previous connection so consumer calls keep failing fast; a teardown
|
|
643
|
+
* racing the adoption aborts without resurrecting anything.
|
|
611
644
|
*/
|
|
612
645
|
private adoptGeneration;
|
|
646
|
+
/**
|
|
647
|
+
* Removes a failed (or torn-down) adoption candidate: stop its wiring,
|
|
648
|
+
* close it bounded, and restore the previous dead connection unless a
|
|
649
|
+
* caller-initiated shutdown already dissolved the runtime (shutdown's own
|
|
650
|
+
* close handled the candidate in that window; the restore must not undo
|
|
651
|
+
* the torn-down state).
|
|
652
|
+
*/
|
|
653
|
+
private rollbackAdoption;
|
|
613
654
|
/**
|
|
614
655
|
* Replays the declarative journal in record order with fresh request ids
|
|
615
656
|
* under the bootstrap deadline class. The resolved default app of the new
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/native-extension-artifact.ts","../src/client.ts","../src/local-broker.ts","../src/transport-supervision.ts","../src/menu-input.ts","../src/sdk.ts","../src/app-icon.ts"],"mappings":";;;;KAcY,mBAAA;AAAA,KACA,qBAAA,MAA2B,MAAA,CAAO,QAAA,IAAY,mBAAmB;AAAA,UAE5D,4BAAA;EACf,WAAA;EACA,WAAW;AAAA;AAAA,UAGI,6BAAA;EACf,cAAA;EACA,mBAAmB;AAAA;AAAA,UAGJ,8BAAA,SACP,6BAAA;EACR,IAAA;EACA,OAAA,EAAS,OAAA,CAAQ,MAAA,CAAO,qBAAA,EAAuB,4BAAA;AAAA;;UAIhC,6BAAA;EACf,WAAW;AAAA;;;;AAhBA;AAGb;;;;cAwBa,uCAAA;AAnBb;AAAA,KA2BY,mCAAA,WACF,uCAAuC;;;;;;;;;;UAWhC,+BAAA,SACP,6BAAA;EACR,IAAA;EACA,OAAA,EAAS,MAAA,CACP,mCAAA,EACA,6BAAA;AAAA;AAAA,UAIM,+BAAA;EACR,IAAA;EACA,IAAI;AAAA;AAAA,KAGM,2BAAA,GAA8B,+BAAA;EAGlC,gBAAA,EAAkB,+BAAA;EAClB,cAAA;AAAA;EAGA,gBAAA;EACA,cAAA,EAAgB,6BAAA;AAAA;AAAA,KAIZ,uBAAA,GACR,8BAAA,GACA,2BAAA,GACA,+BAAA;AAAA,KAEQ,+BAAA,GAAkC,2BAAyB;AAAA,UAEtD,+BAAA;EACf,IAAA;EACA,WAAA;EACA,cAAA;EACA,gBAAA,EAAkB,+BAAA;EAClB,MAAA,EAAQ,qBAAqB;AAAA;AAAA,cAGlB,sCAAA,SAA+C,KAAA;EAAA,SAO/C,MAAA,EAAQ,qBAAA;EAAA,SANV,IAAA;EAAA,SACA,WAAA;EAAA,SACA,oBAAA;cAGP,OAAA,UACS,MAAA,EAAQ,qBAAA,EACjB,OAAA,GAAS,YAAA;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AAW,OAAA,EAAS,aAAA,GAAc,OAAA,CAAQ,UAAA;AAAA;;;;;;AD7CX;AAEhC;KCqDW,sBAAA;EACN,IAAA;EAAmB,MAAA,EAAQ,mBAAA;AAAA;EAC3B,IAAA;EAAkB,WAAA;EAAqB,KAAA,EAAO,MAAM;AAAA;;;;;;;;cAS7C,iBAAA,SAA0B,KAAK;EAAA,SACjC,IAAA;EAAA,SACA,OAAA;cAGP,IAAA,UACA,OAAA,UACA,OAAA;IAAW,OAAA;IAAmB,KAAA;EAAA;AAAA;AAAA,UAWjB,sBAAA,SAA+B,cAAA;EAC9C,UAAA,CAAW,OAAA,EAAS,aAAA,GAAc,OAAA,CAAQ,kBAAA;AAAA;AAAA,UAG3B,UAAA;EACf,MAAA,EAAQ,QAAA;EACR,GAAA,EAAK,SAAA;EACL,SAAA,IAAa,OAAA,CAAQ,kBAAA;EACrB,OAAA,CAAQ,IAAA,EAAM,MAAA,GAAO,OAAA;EACrB,UAAA,CAAW,OAAA,EAAS,SAAA,GAAU,OAAA;EAC9B,OAAA,CAAQ,IAAA,EAAM,MAAA,GAAO,OAAA;EACrB,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA;EAC9C,gBAAA,CAAiB,GAAA,UAAa,IAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/native-extension-artifact.ts","../src/client.ts","../src/local-broker.ts","../src/transport-supervision.ts","../src/menu-input.ts","../src/sdk.ts","../src/app-icon.ts"],"mappings":";;;;KAcY,mBAAA;AAAA,KACA,qBAAA,MAA2B,MAAA,CAAO,QAAA,IAAY,mBAAmB;AAAA,UAE5D,4BAAA;EACf,WAAA;EACA,WAAW;AAAA;AAAA,UAGI,6BAAA;EACf,cAAA;EACA,mBAAmB;AAAA;AAAA,UAGJ,8BAAA,SACP,6BAAA;EACR,IAAA;EACA,OAAA,EAAS,OAAA,CAAQ,MAAA,CAAO,qBAAA,EAAuB,4BAAA;AAAA;;UAIhC,6BAAA;EACf,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BiB,iBAAA;EACf,EAAA;EACA,OAAA,GAAU,SAAA;EACV,IAAA,GAAO,MAAA;EACP,IAAA,GAAO,cAAA;AAAA;;UAIQ,gBAAA,SACP,IAAA,CAAK,kBAAA;EACb,OAAA,CAAQ,IAAA,EAAM,cAAA,GAAiB,OAAA;EAC/B,MAAA,mDACE,SAAA,EAAW,aAAA,CAAc,WAAA,EAAa,QAAA,GACtC,OAAA,GAAU,QAAA,GACT,gBAAA,GAAmB,WAAA;EACtB,OAAA,IAAW,OAAA;AAAA;AAAA,cAGA,UAAA,GACX,OAAA,EAAS,iBAAA,EACT,cAAA,GAAgB,sBAAA,KACf,OAAA,CAAQ,gBAAA;;;cC9DE,wBAAA;AAAA,cAGA,mBAAA,SAA4B,KAAK;EAAA,SACnC,IAAA;EAAA,SACA,MAAA;cAEG,MAAA,UAAgB,QAAA,GAAU,MAAA,CAAO,QAAA;AAAA;AAAA,cAOlC,2BAAA,SAAoC,KAAK;EAAA,SAC3C,IAAA;EAAA,SACA,OAAA;cAEG,OAAA,UAAiB,QAAA,GAAU,MAAA,CAAO,QAAA;AAAA;;cAQnC,eAAA,GACX,IAAA,WACA,QAAA,GAAU,MAAA,CAAO,QAAA,KAChB,OAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -637,10 +637,10 @@ function createTrayHandle(transport, appId, trayId, nextRequestId = createReques
|
|
|
637
637
|
});
|
|
638
638
|
expectResponse(response, requestId, "ack");
|
|
639
639
|
},
|
|
640
|
-
async commandExtension(ext, data) {
|
|
641
|
-
await this.requestExtension(ext, data);
|
|
640
|
+
async commandExtension(ext, data, callOptions) {
|
|
641
|
+
await this.requestExtension(ext, data, callOptions);
|
|
642
642
|
},
|
|
643
|
-
async requestExtension(ext, data) {
|
|
643
|
+
async requestExtension(ext, data, callOptions) {
|
|
644
644
|
const requestId = nextRequestId();
|
|
645
645
|
const response = await transport.request({
|
|
646
646
|
type: "ext-command",
|
|
@@ -649,7 +649,7 @@ function createTrayHandle(transport, appId, trayId, nextRequestId = createReques
|
|
|
649
649
|
trayId,
|
|
650
650
|
ext,
|
|
651
651
|
data
|
|
652
|
-
});
|
|
652
|
+
}, callOptions);
|
|
653
653
|
if (response.type === "ack") {
|
|
654
654
|
expectResponse(response, requestId, "ack");
|
|
655
655
|
return {
|
|
@@ -839,13 +839,13 @@ const createTrayExtensionContext = (tray, appId, extension, options, nextMountId
|
|
|
839
839
|
artifact,
|
|
840
840
|
mountId,
|
|
841
841
|
ensureLoaded,
|
|
842
|
-
async command(data) {
|
|
842
|
+
async command(data, callOptions) {
|
|
843
843
|
await ensureLoaded();
|
|
844
|
-
await tray.commandExtension(mountId, data);
|
|
844
|
+
await tray.commandExtension(mountId, data, callOptions);
|
|
845
845
|
},
|
|
846
|
-
async request(data) {
|
|
846
|
+
async request(data, callOptions) {
|
|
847
847
|
await ensureLoaded();
|
|
848
|
-
return tray.requestExtension(mountId, data);
|
|
848
|
+
return tray.requestExtension(mountId, data, callOptions);
|
|
849
849
|
}
|
|
850
850
|
};
|
|
851
851
|
};
|
|
@@ -2096,6 +2096,7 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2096
2096
|
cooldownMs;
|
|
2097
2097
|
backoffFactor;
|
|
2098
2098
|
backoffCapMs;
|
|
2099
|
+
connectTimeoutMs;
|
|
2099
2100
|
restartApp;
|
|
2100
2101
|
connection;
|
|
2101
2102
|
generation = 0;
|
|
@@ -2108,10 +2109,18 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2108
2109
|
unwireGeneration = noop$1;
|
|
2109
2110
|
heartbeatTimer;
|
|
2110
2111
|
heartbeatOrdinal = 0;
|
|
2112
|
+
heartbeatInFlight = false;
|
|
2111
2113
|
consecutiveHeartbeatFailures = 0;
|
|
2112
2114
|
lastSettledAt = 0;
|
|
2113
2115
|
restartTimestamps = [];
|
|
2114
2116
|
callerInitiated = false;
|
|
2117
|
+
/**
|
|
2118
|
+
* Monotonic teardown epoch: `shutdown()` bumps it so an in-flight recovery
|
|
2119
|
+
* attempt can detect that it raced caller-initiated teardown and abort
|
|
2120
|
+
* instead of resurrecting a destroyed runtime (no candidate adoption, no
|
|
2121
|
+
* `healthy` transition, no restarted heartbeat).
|
|
2122
|
+
*/
|
|
2123
|
+
teardownEpoch = 0;
|
|
2115
2124
|
shutdownPromise;
|
|
2116
2125
|
constructor(connectFactory, options) {
|
|
2117
2126
|
this.connectFactory = connectFactory;
|
|
@@ -2125,6 +2134,7 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2125
2134
|
this.cooldownMs = recovery.cooldownMs ?? 1e3;
|
|
2126
2135
|
this.backoffFactor = recovery.backoffFactor ?? 2;
|
|
2127
2136
|
this.backoffCapMs = recovery.backoffCapMs ?? 3e4;
|
|
2137
|
+
this.connectTimeoutMs = recovery.connectTimeoutMs ?? 1e4;
|
|
2128
2138
|
this.restartApp = recovery.restartApp;
|
|
2129
2139
|
}
|
|
2130
2140
|
/** Current supervision state; edge events go to {@link onTransportStateChange}. */
|
|
@@ -2233,11 +2243,15 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2233
2243
|
/**
|
|
2234
2244
|
* Graceful teardown channel (W4/W3): idempotent, marks the supervision
|
|
2235
2245
|
* caller-initiated synchronously (so the close-driven death event can
|
|
2236
|
-
* never trigger recovery),
|
|
2237
|
-
*
|
|
2246
|
+
* never trigger recovery), bumps the teardown epoch (so an in-flight
|
|
2247
|
+
* recovery attempt aborts instead of resurrecting the runtime), stops the
|
|
2248
|
+
* heartbeat, then closes the current generation — including an
|
|
2249
|
+
* adoption-in-progress candidate routed through `this.connection` —
|
|
2250
|
+
* within its bounded graceful-close budget.
|
|
2238
2251
|
*/
|
|
2239
2252
|
async shutdown() {
|
|
2240
2253
|
this.callerInitiated = true;
|
|
2254
|
+
this.teardownEpoch += 1;
|
|
2241
2255
|
this.shutdownPromise ??= (async () => {
|
|
2242
2256
|
this.stopHeartbeat();
|
|
2243
2257
|
this.unwireGeneration();
|
|
@@ -2270,25 +2284,37 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2270
2284
|
* proves its own liveness, so the probe budget is spent only on silence.
|
|
2271
2285
|
* A probe failure of any rejection class (typed timeout, transport-lost,
|
|
2272
2286
|
* broker error frame) counts; a successful settlement resets the streak.
|
|
2287
|
+
* Single-flight with a generation token: at most one probe per generation
|
|
2288
|
+
* is outstanding (a configured interval shorter than the probe deadline
|
|
2289
|
+
* must not run concurrent probes whose completions double-count), and a
|
|
2290
|
+
* probe that outlives its generation settles nothing.
|
|
2273
2291
|
*/
|
|
2274
2292
|
async heartbeatTick() {
|
|
2293
|
+
if (this.heartbeatInFlight) return;
|
|
2275
2294
|
const connection = this.connection;
|
|
2295
|
+
const probeGeneration = this.generation;
|
|
2276
2296
|
if (connection === void 0 || this.state !== "healthy" || this.callerInitiated) return;
|
|
2277
2297
|
if (Date.now() - this.lastSettledAt < this.heartbeatIntervalMs) return;
|
|
2298
|
+
this.heartbeatInFlight = true;
|
|
2278
2299
|
const requestId = `supervisor-heartbeat-${this.generation}-${this.heartbeatOrdinal += 1}`;
|
|
2279
2300
|
try {
|
|
2280
2301
|
await connection.request({
|
|
2281
2302
|
type: "health",
|
|
2282
2303
|
requestId
|
|
2283
2304
|
}, { deadlineMs: this.probeDeadlineMs });
|
|
2284
|
-
this.
|
|
2285
|
-
|
|
2305
|
+
if (this.generation === probeGeneration && this.state === "healthy") {
|
|
2306
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
2307
|
+
this.noteSuccessfulSettlement();
|
|
2308
|
+
}
|
|
2286
2309
|
} catch (error) {
|
|
2310
|
+
if (this.generation !== probeGeneration || this.state !== "healthy") return;
|
|
2287
2311
|
this.consecutiveHeartbeatFailures += 1;
|
|
2288
2312
|
if (this.consecutiveHeartbeatFailures < this.heartbeatFailureThreshold) return;
|
|
2289
2313
|
const death = new Error(BROKER_CONNECTION_CLOSED_MESSAGE, { cause: `heartbeat declared death after ${this.consecutiveHeartbeatFailures} consecutive probe failures (${String(error)})` });
|
|
2290
2314
|
this.handleGenerationDeath(death);
|
|
2291
2315
|
connection.close().catch(noopAsync);
|
|
2316
|
+
} finally {
|
|
2317
|
+
this.heartbeatInFlight = false;
|
|
2292
2318
|
}
|
|
2293
2319
|
}
|
|
2294
2320
|
noteSuccessfulSettlement() {
|
|
@@ -2374,7 +2400,10 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2374
2400
|
* original connect options → journal replay → facade rebuilds → healthy.
|
|
2375
2401
|
* Every attempt consumes budget up front; a failed attempt (connect,
|
|
2376
2402
|
* replay, or rebuild — including artifact identity mismatches) retries
|
|
2377
|
-
* inside the remaining budget until exhaustion abandons the runtime.
|
|
2403
|
+
* inside the remaining budget until exhaustion abandons the runtime. Each
|
|
2404
|
+
* reconnect attempt is bounded by the connect budget, and every step
|
|
2405
|
+
* re-checks the teardown epoch so a shutdown racing the loop aborts it
|
|
2406
|
+
* instead of resurrecting the runtime.
|
|
2378
2407
|
*/
|
|
2379
2408
|
async runRecovery() {
|
|
2380
2409
|
this.setState("recovering");
|
|
@@ -2387,9 +2416,15 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2387
2416
|
}
|
|
2388
2417
|
await sleepUnref(this.cooldownForBackoff(backoffOrdinal));
|
|
2389
2418
|
if (this.callerInitiated) return;
|
|
2419
|
+
const attemptEpoch = this.teardownEpoch;
|
|
2390
2420
|
try {
|
|
2391
|
-
const candidate = await this.
|
|
2392
|
-
|
|
2421
|
+
const candidate = await this.connectWithBudget();
|
|
2422
|
+
if (this.teardownEpoch !== attemptEpoch || this.callerInitiated) {
|
|
2423
|
+
await candidate.close().catch(noopAsync);
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
await this.adoptGeneration(candidate, attemptEpoch);
|
|
2427
|
+
if (this.teardownEpoch !== attemptEpoch || this.callerInitiated) return;
|
|
2393
2428
|
this.setState("healthy");
|
|
2394
2429
|
return;
|
|
2395
2430
|
} catch {
|
|
@@ -2397,6 +2432,39 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2397
2432
|
}
|
|
2398
2433
|
}
|
|
2399
2434
|
}
|
|
2435
|
+
/**
|
|
2436
|
+
* One reconnect attempt under the connect budget. A factory that never
|
|
2437
|
+
* settles counts as a failed attempt; a connection arriving after the
|
|
2438
|
+
* budget expired is closed on arrival so no orphan generation leaks.
|
|
2439
|
+
*/
|
|
2440
|
+
async connectWithBudget() {
|
|
2441
|
+
let settled = false;
|
|
2442
|
+
return new Promise((resolve, reject) => {
|
|
2443
|
+
const late = (candidate) => {
|
|
2444
|
+
candidate.close().catch(noopAsync);
|
|
2445
|
+
};
|
|
2446
|
+
const timer = setTimeout(() => {
|
|
2447
|
+
if (settled) return;
|
|
2448
|
+
settled = true;
|
|
2449
|
+
reject(/* @__PURE__ */ new Error(`recovery connect exceeded ${this.connectTimeoutMs}ms`));
|
|
2450
|
+
}, this.connectTimeoutMs);
|
|
2451
|
+
timer.unref();
|
|
2452
|
+
this.connectFactory().then((candidate) => {
|
|
2453
|
+
if (settled) {
|
|
2454
|
+
late(candidate);
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
settled = true;
|
|
2458
|
+
clearTimeout(timer);
|
|
2459
|
+
resolve(candidate);
|
|
2460
|
+
}, (error) => {
|
|
2461
|
+
if (settled) return;
|
|
2462
|
+
settled = true;
|
|
2463
|
+
clearTimeout(timer);
|
|
2464
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2465
|
+
});
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2400
2468
|
cooldownForBackoff(backoffOrdinal) {
|
|
2401
2469
|
return Math.min(this.cooldownMs * this.backoffFactor ** backoffOrdinal, this.backoffCapMs);
|
|
2402
2470
|
}
|
|
@@ -2414,32 +2482,50 @@ var SupervisedLocalBrokerConnection = class {
|
|
|
2414
2482
|
}
|
|
2415
2483
|
/**
|
|
2416
2484
|
* Wires the candidate generation, replays the journal, and runs the
|
|
2417
|
-
* facade rebuild callbacks. `this.connection`
|
|
2418
|
-
*
|
|
2419
|
-
*
|
|
2420
|
-
*
|
|
2421
|
-
*
|
|
2485
|
+
* facade rebuild callbacks. The candidate becomes `this.connection` for
|
|
2486
|
+
* the adoption's duration — facade rebuild callbacks route their
|
|
2487
|
+
* re-creation commands through this supervisor, so they must reach the
|
|
2488
|
+
* candidate, not the dead generation (the rebuild-routing law). A failure
|
|
2489
|
+
* rolls the candidate back out (unwired, closed) and restores the dead
|
|
2490
|
+
* previous connection so consumer calls keep failing fast; a teardown
|
|
2491
|
+
* racing the adoption aborts without resurrecting anything.
|
|
2422
2492
|
*/
|
|
2423
|
-
async adoptGeneration(candidate) {
|
|
2493
|
+
async adoptGeneration(candidate, attemptEpoch) {
|
|
2494
|
+
const previousConnection = this.connection;
|
|
2424
2495
|
this.generation += 1;
|
|
2425
2496
|
this.unwireGeneration = this.wireGeneration(candidate);
|
|
2497
|
+
this.connection = candidate;
|
|
2426
2498
|
try {
|
|
2427
2499
|
await this.replayJournal(candidate);
|
|
2428
2500
|
for (const rebuild of [...this.rebuildCallbacks]) await rebuild({
|
|
2429
2501
|
generation: this.generation,
|
|
2430
2502
|
sessionId: candidate.sessionId.length > 0 ? candidate.sessionId : void 0
|
|
2431
2503
|
});
|
|
2504
|
+
if (this.teardownEpoch !== attemptEpoch || this.callerInitiated) {
|
|
2505
|
+
this.rollbackAdoption(candidate, previousConnection);
|
|
2506
|
+
throw new Error("recovery aborted by caller-initiated teardown");
|
|
2507
|
+
}
|
|
2432
2508
|
} catch (error) {
|
|
2433
|
-
this.
|
|
2434
|
-
this.unwireGeneration = noop$1;
|
|
2435
|
-
await candidate.close().catch(noopAsync);
|
|
2509
|
+
this.rollbackAdoption(candidate, previousConnection);
|
|
2436
2510
|
throw error;
|
|
2437
2511
|
}
|
|
2438
|
-
this.connection = candidate;
|
|
2439
2512
|
this.consecutiveHeartbeatFailures = 0;
|
|
2440
2513
|
this.noteSuccessfulSettlement();
|
|
2441
2514
|
}
|
|
2442
2515
|
/**
|
|
2516
|
+
* Removes a failed (or torn-down) adoption candidate: stop its wiring,
|
|
2517
|
+
* close it bounded, and restore the previous dead connection unless a
|
|
2518
|
+
* caller-initiated shutdown already dissolved the runtime (shutdown's own
|
|
2519
|
+
* close handled the candidate in that window; the restore must not undo
|
|
2520
|
+
* the torn-down state).
|
|
2521
|
+
*/
|
|
2522
|
+
rollbackAdoption(candidate, previousConnection) {
|
|
2523
|
+
this.unwireGeneration();
|
|
2524
|
+
this.unwireGeneration = noop$1;
|
|
2525
|
+
if (this.connection === candidate) this.connection = this.callerInitiated ? void 0 : previousConnection;
|
|
2526
|
+
candidate.close().catch(noopAsync);
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2443
2529
|
* Replays the declarative journal in record order with fresh request ids
|
|
2444
2530
|
* under the bootstrap deadline class. The resolved default app of the new
|
|
2445
2531
|
* generation becomes the appId authority: replayed frames are rewritten
|