Skip to content

Commit 64c8368

Browse files
authored
fix(js-sdk): shutdown circuit breaker during client disposal (#7297)
1 parent ac592d1 commit 64c8368

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.changeset/great-boxes-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/core': patch
3+
---
4+
5+
Shutdown Circuit Breaker properly while disposing Hive Client

packages/libraries/core/src/client/agent.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,25 @@ export function createAgent<TEvent>(
253253
skipSchedule: true,
254254
throwOnError: false,
255255
});
256+
257+
circuitBreaker.shutdown();
256258
}
257259

258260
if (options.circuitBreaker) {
259-
circuitBreaker = new CircuitBreaker(sendHTTPCall, {
261+
const circuitBreakerInstance = new CircuitBreaker(sendHTTPCall, {
260262
...options.circuitBreaker,
261263
timeout: false,
262264
autoRenewAbortController: true,
263265
});
266+
circuitBreaker = circuitBreakerInstance;
264267

265-
(circuitBreaker as any).on('open', () =>
268+
circuitBreakerInstance.on('open', () =>
266269
breakerLogger.error('circuit opened - backend seems unreachable.'),
267270
);
268-
(circuitBreaker as any).on('halfOpen', () =>
271+
circuitBreakerInstance.on('halfOpen', () =>
269272
breakerLogger.info('circuit half open - testing backend connectivity'),
270273
);
271-
(circuitBreaker as any).on('close', () =>
274+
circuitBreakerInstance.on('close', () =>
272275
breakerLogger.info('circuit closed - backend recovered '),
273276
);
274277
} else {
@@ -277,6 +280,7 @@ export function createAgent<TEvent>(
277280
return undefined;
278281
},
279282
fire: sendHTTPCall,
283+
shutdown() {},
280284
};
281285
}
282286

@@ -303,4 +307,5 @@ export function createAgent<TEvent>(
303307
type CircuitBreakerInterface<TI extends unknown[] = unknown[], TR = unknown> = {
304308
fire(...args: TI): TR;
305309
getSignal(): AbortSignal | undefined;
310+
shutdown(): void;
306311
};

0 commit comments

Comments
 (0)