Skip to content

Commit

Permalink
Fix race condition in profiling plugin.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samccone committed Jun 23, 2018
1 parent 3fb49de commit 735f99c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/debug/ProfilingPlugin.js
Expand Up @@ -130,7 +130,14 @@ function createTrace(outputPath) {
trace,
counter,
profiler,
end: callback => fsStream.end(callback)
end: callback => {
// Wait until the write stream finishes.
fsStream.on("finish", () => {
callback();
});
// Tear down the readable trace stream.
trace.destroy();
}
};
}

Expand Down

0 comments on commit 735f99c

Please sign in to comment.