diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 118d5007de3..bd6202fdbdb 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -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(); + } }; }