@@ -14,6 +14,7 @@ const MIN_SEVERITY = "high";
|
14 | 14 | export const BULK_ADVISORY_ERROR_BODY_MAX_CHARS = 4096; |
15 | 15 | export const BULK_ADVISORY_RESPONSE_BODY_MAX_BYTES = 8 * 1024 * 1024; |
16 | 16 | export const BULK_ADVISORY_REQUEST_TIMEOUT_MS = 60_000; |
| 17 | +const MAX_TIMER_TIMEOUT_MS = 2_147_000_000; |
17 | 18 | const SEVERITY_RANK = { |
18 | 19 | info: 0, |
19 | 20 | low: 1, |
@@ -695,9 +696,11 @@ function parsePositiveIntegerEnv(name, fallback) {
|
695 | 696 | } |
696 | 697 | |
697 | 698 | function resolveBulkAdvisoryRequestTimeoutMs() { |
698 | | -return parsePositiveIntegerEnv( |
699 | | -"OPENCLAW_PNPM_AUDIT_BULK_TIMEOUT_MS", |
700 | | -BULK_ADVISORY_REQUEST_TIMEOUT_MS, |
| 699 | +return clampTimerTimeoutMs( |
| 700 | +parsePositiveIntegerEnv( |
| 701 | +"OPENCLAW_PNPM_AUDIT_BULK_TIMEOUT_MS", |
| 702 | +BULK_ADVISORY_REQUEST_TIMEOUT_MS, |
| 703 | +), |
701 | 704 | ); |
702 | 705 | } |
703 | 706 | |
@@ -708,15 +711,21 @@ function resolveBulkAdvisoryResponseBodyMaxBytes() {
|
708 | 711 | ); |
709 | 712 | } |
710 | 713 | |
| 714 | +function clampTimerTimeoutMs(valueMs) { |
| 715 | +const value = Number.isFinite(valueMs) ? valueMs : BULK_ADVISORY_REQUEST_TIMEOUT_MS; |
| 716 | +return Math.min(Math.max(Math.floor(value), 1), MAX_TIMER_TIMEOUT_MS); |
| 717 | +} |
| 718 | + |
711 | 719 | async function withBulkAdvisoryTimeout({ label, timeoutMs, run }) { |
| 720 | +const resolvedTimeoutMs = clampTimerTimeoutMs(timeoutMs); |
712 | 721 | const controller = new AbortController(); |
713 | 722 | let timeout; |
714 | 723 | const timeoutPromise = new Promise((_resolve, reject) => { |
715 | 724 | timeout = setTimeout(() => { |
716 | | -const error = new Error(`${label} exceeded timeout of ${timeoutMs}ms`); |
| 725 | +const error = new Error(`${label} exceeded timeout of ${resolvedTimeoutMs}ms`); |
717 | 726 | controller.abort(error); |
718 | 727 | reject(error); |
719 | | -}, timeoutMs); |
| 728 | +}, resolvedTimeoutMs); |
720 | 729 | }); |
721 | 730 | try { |
722 | 731 | return await Promise.race([run({ signal: controller.signal, timeoutPromise }), timeoutPromise]); |
|