Skip to content

Commit e9c3c7a

Browse files
committed
Only unref the timeout after the promise has completed
1 parent 208a419 commit e9c3c7a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/telemetry/telemetry.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,23 @@ export class Telemetry {
9494
});
9595

9696
// Wait up to 5 seconds for events to be sent before closing, but don't throw if it times out
97-
const flushTimeout = 5000;
97+
const flushMaxWaitTime = 5000;
98+
let flushTimeout: NodeJS.Timeout | undefined;
9899
await Promise.race([
99100
new Promise<void>((resolve) => {
100-
const timeout = setTimeout(() => {
101+
flushTimeout = setTimeout(() => {
101102
this.session.logger.debug({
102103
id: LogId.telemetryClose,
103-
message: `Failed to flush remaining events within ${flushTimeout}ms timeout`,
104+
message: `Failed to flush remaining events within ${flushMaxWaitTime}ms timeout`,
104105
context: "telemetry",
105106
});
106107
resolve();
107-
}, flushTimeout);
108-
timeout.unref();
108+
}, flushMaxWaitTime);
109109
}),
110110
this.emit([]),
111111
]);
112+
113+
flushTimeout?.unref();
112114
}
113115

114116
/**

0 commit comments

Comments
 (0)