Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit b2fd95d

Browse files
authored
fix: unref ExporterBuffer flush timer (#25)
1 parent 84ad67e commit b2fd95d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/opencensus-core/src/exporters/exporter-buffer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class ExporterBuffer {
100100
this.logger.debug('ExporterBuffer: set timeout');
101101
this.bufferTimeoutInProgress = true;
102102

103-
setTimeout(() => {
103+
const timer = setTimeout(() => {
104104
if (this.queue.length === 0) {
105105
return;
106106
}
@@ -113,6 +113,8 @@ export class ExporterBuffer {
113113
this.flush();
114114
}
115115
}, this.bufferTimeout);
116+
// Don't let this timer be the only thing keeping the process alive
117+
timer.unref();
116118
}
117119

118120
/** Send the trace queue to all exporters */

packages/opencensus-core/test/test-exporter-buffer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ describe('ExporterBuffer', () => {
105105
* Should flush by timeout
106106
*/
107107
describe('addToBuffer force flush by timeout ', () => {
108-
it('should flush by timeout', () => {
108+
it('should flush by timeout', (done) => {
109109
const buffer = new ExporterBuffer(exporter, defaultBufferConfig);
110110
buffer.addToBuffer(new RootSpan(tracer));
111111
assert.strictEqual(buffer.getQueue().length, 1);
112112
setTimeout(() => {
113113
assert.strictEqual(buffer.getQueue().length, 0);
114+
done();
114115
}, DEFAULT_BUFFER_TIMEOUT + 100);
115-
});
116+
}).timeout(5000);
116117
});
117-
});
118+
});

0 commit comments

Comments
 (0)