davidmarkclements / 0x

🔥 single-command flamegraph profiling 🔥
MIT License
3.23k stars 106 forks source link

Don't leave isolate log debris if command execution hits error #182

Closed AlanSl closed 6 years ago

AlanSl commented 6 years ago

Depending on when the error occurs, it's possible for 0x's collect branch using the V8 platform to leave V8 isolate log files lying around in the main working directory after exit. This causes problems such as filling up CI servers of tools that use 0x and have tests for their own handlers for such errors.

To replicate, try running this from the command line. An isolate log file will be created and will persist after completion:

0x -- node -e 'setTimeout(() => { fail() }, 1000)'

This PR adds a cleanup error handler that deletes any such log if there is an error in the V8 process. Run the above command in this branch while watching the working directory and you should be able to see the isolate log file be created, then deleted after a second when the error is hit.

AlanSl commented 6 years ago

Latest commit switches off this behaviour if debugging is enabled as per the 0x docs, and puts a message in the console informing the user (unless --quiet or --silent are passed).

For example, this hits an error, deletes the log, and gives the user a message:

0x -- node -e 'setTimeout(() => { fail() }, 1000)'
# deletes log, outputs "Fatal error in process observed by 0x. Incomplete V8 isolate log deleted. To preserve these logs, enable debugging (e.g. `DEBUG=0x* 0x my-app.js`)"

0x --quiet -- node -e 'setTimeout(() => { fail() }, 1000)'
# deletes log, outputs nothing except error details

DEBUG=0x* 0x -- node -e 'setTimeout(() => { fail() }, 1000)'
# preserves log, outputs like "Fatal error in process observed by 0x. Incomplete V8 isolate log is readable for debugging at /some/path/isolate-0x1234567890-1234-v8.log"

DEBUG=0x* 0x --quiet -- node -e 'setTimeout(() => { fail() }, 1000)'
# preserves log, outputs nothing except error details