fix(js-sdk): shutdown circuit breaker during client disposal (#7297)

This commit is contained in:
Arda TANRIKULU 2025-11-21 02:45:32 +03:00 committed by GitHub
parent ac592d1d53
commit 64c8368c4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/core': patch
---
Shutdown Circuit Breaker properly while disposing Hive Client

View file

@ -253,22 +253,25 @@ export function createAgent<TEvent>(
skipSchedule: true,
throwOnError: false,
});
circuitBreaker.shutdown();
}
if (options.circuitBreaker) {
circuitBreaker = new CircuitBreaker(sendHTTPCall, {
const circuitBreakerInstance = new CircuitBreaker(sendHTTPCall, {
...options.circuitBreaker,
timeout: false,
autoRenewAbortController: true,
});
circuitBreaker = circuitBreakerInstance;
(circuitBreaker as any).on('open', () =>
circuitBreakerInstance.on('open', () =>
breakerLogger.error('circuit opened - backend seems unreachable.'),
);
(circuitBreaker as any).on('halfOpen', () =>
circuitBreakerInstance.on('halfOpen', () =>
breakerLogger.info('circuit half open - testing backend connectivity'),
);
(circuitBreaker as any).on('close', () =>
circuitBreakerInstance.on('close', () =>
breakerLogger.info('circuit closed - backend recovered '),
);
} else {
@ -277,6 +280,7 @@ export function createAgent<TEvent>(
return undefined;
},
fire: sendHTTPCall,
shutdown() {},
};
}
@ -303,4 +307,5 @@ export function createAgent<TEvent>(
type CircuitBreakerInterface<TI extends unknown[] = unknown[], TR = unknown> = {
fire(...args: TI): TR;
getSignal(): AbortSignal | undefined;
shutdown(): void;
};