mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
fix(js-sdk): shutdown circuit breaker during client disposal (#7297)
This commit is contained in:
parent
ac592d1d53
commit
64c8368c4b
2 changed files with 14 additions and 4 deletions
5
.changeset/great-boxes-buy.md
Normal file
5
.changeset/great-boxes-buy.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/core': patch
|
||||
---
|
||||
|
||||
Shutdown Circuit Breaker properly while disposing Hive Client
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue