taist 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/trace-reporter.js +10 -2
- package/package.json +1 -1
package/lib/trace-reporter.js
CHANGED
|
@@ -30,6 +30,7 @@ export class TraceReporter extends EventEmitter {
|
|
|
30
30
|
this.flushTimer = null;
|
|
31
31
|
this.workerId = options.workerId || process.pid;
|
|
32
32
|
this.closed = false;
|
|
33
|
+
this.shuttingDown = false; // Prevents race between shutdown signal and SIGTERM
|
|
33
34
|
|
|
34
35
|
logger.debug("[reporter] Created with socketPath:", this.socketPath);
|
|
35
36
|
|
|
@@ -41,7 +42,12 @@ export class TraceReporter extends EventEmitter {
|
|
|
41
42
|
|
|
42
43
|
_setupExitHandlers() {
|
|
43
44
|
const cleanup = (signal) => {
|
|
44
|
-
logger.debug("[reporter] Cleanup triggered by:", signal, "buffer size:", this.buffer.length);
|
|
45
|
+
logger.debug("[reporter] Cleanup triggered by:", signal, "buffer size:", this.buffer.length, "shuttingDown:", this.shuttingDown);
|
|
46
|
+
// If shutdown signal handler is already handling graceful shutdown, don't interfere
|
|
47
|
+
if (this.shuttingDown) {
|
|
48
|
+
logger.debug("[reporter] Shutdown already in progress, skipping cleanup");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
45
51
|
if (!this.closed) {
|
|
46
52
|
this.flushSync();
|
|
47
53
|
this.close();
|
|
@@ -155,8 +161,10 @@ export class TraceReporter extends EventEmitter {
|
|
|
155
161
|
* Flushes buffer and waits for data to be sent before closing.
|
|
156
162
|
*/
|
|
157
163
|
_handleShutdown() {
|
|
158
|
-
if (this.closed) return;
|
|
164
|
+
if (this.closed || this.shuttingDown) return;
|
|
159
165
|
|
|
166
|
+
// Set flag immediately to prevent exit handlers from interfering
|
|
167
|
+
this.shuttingDown = true;
|
|
160
168
|
this._stopFlushTimer();
|
|
161
169
|
|
|
162
170
|
// Flush and wait for data to be sent
|