diff options
author | legendecas <legendecas@gmail.com> | 2019-11-17 15:02:01 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-12-18 02:21:12 +0300 |
commit | d8ce9a0e234660d268f60fb55b156aebfaf29310 (patch) | |
tree | b34d2b4ac4f2089f28c36d0ba2dcca9493853c87 /src/env.cc | |
parent | 510edead69d2ea3288ee7e76e352d937cd997c30 (diff) |
cli: add --trace-exit cli option
It could be convenient to trace abnormal exit of the Node.js processes
that printing stacktrace on each `process.exit` call with a cli option.
This also takes effects on worker threads.
PR-URL: https://github.com/nodejs/node/pull/30516
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc index bf3420f826f..f3d71c61c09 100644 --- a/src/env.cc +++ b/src/env.cc @@ -940,6 +940,21 @@ void AsyncHooks::grow_async_ids_stack() { uv_key_t Environment::thread_local_env = {}; void Environment::Exit(int exit_code) { + if (options()->trace_exit) { + HandleScope handle_scope(isolate()); + + if (is_main_thread()) { + fprintf(stderr, "(node:%d) ", uv_os_getpid()); + } else { + fprintf(stderr, "(node:%d, thread:%llu) ", uv_os_getpid(), thread_id()); + } + + fprintf( + stderr, "WARNING: Exited the environment with code %d\n", exit_code); + PrintStackTrace( + isolate(), + StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed)); + } if (is_main_thread()) { stop_sub_worker_contexts(); DisposePlatform(); |