GeezerVison is showing github.com — src: fix fatal errors when a current isolate not exist · acohn/node@f536cc2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_errors.cc +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -425,6 +425,12 @@ void OnFatalError(const char* location, const char* message) { | 425 | 425 | } | 426 | 426 |
| 427 | 427 | Isolate* isolate = Isolate::GetCurrent(); | | 428 | + // TODO(legendecas): investigate failures on triggering node-report with | | 429 | + // nullptr isolates. | | 430 | + if (isolate == nullptr) { | | 431 | + fflush(stderr); | | 432 | + ABORT(); | | 433 | + } | 428 | 434 | Environment* env = Environment::GetCurrent(isolate); | 429 | 435 | bool report_on_fatalerror; | 430 | 436 | { | |
Collapse file Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,3 +16,4 @@ const p = child_process.spawnSync( | 16 | 16 | assert.ifError(p.error); | 17 | 17 | assert.ok(p.stderr.toString().includes( | 18 | 18 | 'FATAL ERROR: test_fatal::Test fatal message')); | | 19 | +assert.ok(p.status === 134 || p.signal === 'SIGABRT'); |
Collapse file Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test2.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,3 +16,4 @@ const p = child_process.spawnSync( | 16 | 16 | assert.ifError(p.error); | 17 | 17 | assert.ok(p.stderr.toString().includes( | 18 | 18 | 'FATAL ERROR: test_fatal::Test fatal message')); | | 19 | +assert.ok(p.status === 134 || p.signal === 'SIGABRT'); |
Collapse file Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test_fatal.c +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// For the purpose of this test we use libuv's threading library. When deciding | | 2 | +// on a threading library for a new project it bears remembering that in the | | 3 | +// future libuv may introduce API changes which may render it non-ABI-stable, | | 4 | +// which, in turn, may affect the ABI stability of the project despite its use | | 5 | +// of N-API. | | 6 | +#include <uv.h> | 1 | 7 | #include <node_api.h> | 2 | 8 | #include "../../js-native-api/common.h" | 3 | 9 |
| | 10 | +static uv_thread_t uv_thread; | | 11 | + | | 12 | +static void work_thread(void* data) { | | 13 | + napi_fatal_error("work_thread", NAPI_AUTO_LENGTH, | | 14 | + "foobar", NAPI_AUTO_LENGTH); | | 15 | +} | | 16 | + | 4 | 17 | static napi_value Test(napi_env env, napi_callback_info info) { | 5 | 18 | napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH, | 6 | 19 | "fatal message", NAPI_AUTO_LENGTH); | 7 | 20 | return NULL; | 8 | 21 | } | 9 | 22 |
| | 23 | +static napi_value TestThread(napi_env env, napi_callback_info info) { | | 24 | + NODE_API_ASSERT(env, | | 25 | + (uv_thread_create(&uv_thread, work_thread, NULL) == 0), | | 26 | + "Thread creation"); | | 27 | + return NULL; | | 28 | +} | | 29 | + | 10 | 30 | static napi_value TestStringLength(napi_env env, napi_callback_info info) { | 11 | 31 | napi_fatal_error("test_fatal::TestStringLength", 16, "fatal message", 13); | 12 | 32 | return NULL; | @@ -16,6 +36,7 @@ static napi_value Init(napi_env env, napi_value exports) { | 16 | 36 | napi_property_descriptor properties[] = { | 17 | 37 | DECLARE_NODE_API_PROPERTY("Test", Test), | 18 | 38 | DECLARE_NODE_API_PROPERTY("TestStringLength", TestStringLength), | | 39 | + DECLARE_NODE_API_PROPERTY("TestThread", TestThread), | 19 | 40 | }; | 20 | 41 |
| 21 | 42 | NODE_API_CALL(env, napi_define_properties( | |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../../common'); | | 3 | +const assert = require('assert'); | | 4 | +const child_process = require('child_process'); | | 5 | +const test_fatal = require(`./build/${common.buildType}/test_fatal`); | | 6 | + | | 7 | +// Test in a child process because the test code will trigger a fatal error | | 8 | +// that crashes the process. | | 9 | +if (process.argv[2] === 'child') { | | 10 | + test_fatal.TestThread(); | | 11 | + // Busy loop to allow the work thread to abort. | | 12 | + while (true) {} | | 13 | +} | | 14 | + | | 15 | +const p = child_process.spawnSync( | | 16 | + process.execPath, [ __filename, 'child' ]); | | 17 | +assert.ifError(p.error); | | 18 | +assert.ok(p.stderr.toString().includes( | | 19 | + 'FATAL ERROR: work_thread foobar')); | | 20 | +assert.ok(p.status === 134 || p.signal === 'SIGABRT'); |
|