fix(process): use monotonic time for provider execution budgets

This commit is contained in:
morluto
2026-10-13 15:01:59 +08:00
parent b953f96c0a
commit d9e9fb2273
6 changed files with 47 additions and 12 deletions
+4 -4
View File
@@ -42,11 +42,11 @@ export class ProviderStartupDeadline {
) {
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
throw new RangeError("Provider startup timeout must be positive");
this.#deadlineAt = Date.now() + timeoutMs;
this.#deadlineAt = performance.now() + timeoutMs;
this.#externalSignal = signal;
this.#onExternalAbort = () => {
if (this.#controller.signal.aborted) return;
if (Date.now() >= this.#deadlineAt) {
if (performance.now() >= this.#deadlineAt) {
this.#interruption = "timeout";
this.#abort(
new DOMException("Provider startup deadline elapsed", "TimeoutError"),
@@ -79,13 +79,13 @@ export class ProviderStartupDeadline {
get interruption(): "cancelled" | "timeout" | undefined {
return (
this.#interruption ??
(Date.now() >= this.#deadlineAt ? "timeout" : undefined)
(performance.now() >= this.#deadlineAt ? "timeout" : undefined)
);
}
/** Milliseconds still available to the next startup phase. */
remainingMs(): number {
return Math.max(0, this.#deadlineAt - Date.now());
return Math.max(0, Math.ceil(this.#deadlineAt - performance.now()));
}
/** Wait for at most one polling interval under the shared deadline signal. */