Skip to content

Commit d2573f5

Browse files
committed
Properly wait for interceptor deactivation at shutdown
Previously due to a missing await we didn't actually wait at all, we just started it and then exited anyway. Now we wait up to 2 seconds.
1 parent 0d33560 commit d2573f5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/shutdown.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { reportError } from './error-tracking';
2+
import { delay } from './util';
23

34
type ShutdownHandler = () => Promise<unknown>;
45
const shutdownHandlers: Array<ShutdownHandler> = [];
@@ -15,16 +16,21 @@ export function addShutdownHandler(handler: ShutdownHandler) {
1516
async function shutdown() {
1617
console.log('Shutting down...');
1718

18-
await Promise.all(shutdownHandlers.map(
19+
const shutdownPromises = Promise.all(shutdownHandlers.map(
1920
async (handler) => {
2021
try {
21-
handler();
22+
await handler();
2223
} catch (e) {
2324
reportError(e);
2425
}
2526
}
2627
));
2728

29+
await Promise.race([
30+
shutdownPromises,
31+
delay(2000) // After 2 seconds, we just close anyway, we're done.
32+
]);
33+
2834
process.exit(0);
2935
}
3036

0 commit comments

Comments
 (0)