Skip to content

Commit 735f99c

Browse files
committed
Fix race condition in profiling plugin.
Based on some digging in this git history for the profiling plugin it looks like this commit exacerbated the issue: 883088e Note, we are calling end() and then writeStream right after we call flush on the trace object https://github.com/samccone/chrome-trace-event/blob/64b514e9bd364ca5b6df3c0fb121ba0d3b239cc2/lib/trace-event.ts#L123 The trace object is only calling _push to the writable stream but in no way ensuring that all data that has been pushed has actually been written to the output stream sooo we find ourselves encounter 🐎 [race] conditions.
1 parent 3fb49de commit 735f99c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/debug/ProfilingPlugin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ function createTrace(outputPath) {
130130
trace,
131131
counter,
132132
profiler,
133-
end: callback => fsStream.end(callback)
133+
end: callback => {
134+
// Wait until the write stream finishes.
135+
fsStream.on("finish", () => {
136+
callback();
137+
});
138+
// Tear down the readable trace stream.
139+
trace.destroy();
140+
}
134141
};
135142
}
136143

0 commit comments

Comments
 (0)