Interrupt live traffic retry delays on stop
This commit is contained in:
@@ -639,10 +639,17 @@ function defaultClientFactory(port: number): NativeTrafficClient {
|
||||
}));
|
||||
}
|
||||
|
||||
function delay(milliseconds: number) {
|
||||
function delay(milliseconds: number, signal: AbortSignal) {
|
||||
return new Promise<void>((resolve) => {
|
||||
const timer = setTimeout(resolve, milliseconds);
|
||||
const finish = () => {
|
||||
clearTimeout(timer);
|
||||
signal.removeEventListener('abort', finish);
|
||||
resolve();
|
||||
};
|
||||
const timer = setTimeout(finish, milliseconds);
|
||||
timer.unref();
|
||||
signal.addEventListener('abort', finish, { once: true });
|
||||
if (signal.aborted) finish();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -660,6 +667,7 @@ export function createLiveTrafficService({
|
||||
const ledger = createLiveTrafficLedger({ enabled, gateway, resolveOrigin });
|
||||
if (!enabled && unavailableError) ledger.markUnavailable(unavailableError);
|
||||
let stopped = false;
|
||||
const stopController = new AbortController();
|
||||
let controller: AbortController | null = null;
|
||||
let running: Promise<void> | null = null;
|
||||
let failedProjection: NativeTrafficProjectionBatch | null = null;
|
||||
@@ -742,7 +750,7 @@ export function createLiveTrafficService({
|
||||
while (!stopped) {
|
||||
if (!isRuntimeRunning()) {
|
||||
ledger.markStopped();
|
||||
await delay(RETRY_MS);
|
||||
await delay(RETRY_MS, stopController.signal);
|
||||
continue;
|
||||
}
|
||||
controller = new AbortController();
|
||||
@@ -756,7 +764,7 @@ export function createLiveTrafficService({
|
||||
} finally {
|
||||
controller = null;
|
||||
}
|
||||
if (!stopped) await delay(RETRY_MS);
|
||||
if (!stopped) await delay(RETRY_MS, stopController.signal);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -767,6 +775,7 @@ export function createLiveTrafficService({
|
||||
},
|
||||
async stop() {
|
||||
stopped = true;
|
||||
stopController.abort();
|
||||
controller?.abort();
|
||||
await running;
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const HARBOR_VERSIONS = Object.freeze({
|
||||
macClient: '0.34.0',
|
||||
gatewayClient: '0.36.0',
|
||||
gatewayBackend: '0.36.0',
|
||||
macClient: '0.34.1',
|
||||
gatewayClient: '0.36.1',
|
||||
gatewayBackend: '0.36.1',
|
||||
});
|
||||
|
||||
export interface ParsedVersion {
|
||||
|
||||
Reference in New Issue
Block a user