GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: fix fatal errors when a current isolate not exist · fredericp/node@f536cc2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_errors.cc
  • test/node-api/test_fatal
    • test.js
    • test2.js
    • test_fatal.c
    • test_threads.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_errors.cc‎

Copy file name to clipboardExpand all lines: src/node_errors.cc
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ void OnFatalError(const char* location, const char* message) {
425425
}
426426

427427
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+
}
428434
Environment* env = Environment::GetCurrent(isolate);
429435
bool report_on_fatalerror;
430436
{
Collapse file

‎test/node-api/test_fatal/test.js‎

Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ const p = child_process.spawnSync(
1616
assert.ifError(p.error);
1717
assert.ok(p.stderr.toString().includes(
1818
'FATAL ERROR: test_fatal::Test fatal message'));
19+
assert.ok(p.status === 134 || p.signal === 'SIGABRT');
Collapse file

‎test/node-api/test_fatal/test2.js‎

Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test2.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ const p = child_process.spawnSync(
1616
assert.ifError(p.error);
1717
assert.ok(p.stderr.toString().includes(
1818
'FATAL ERROR: test_fatal::Test fatal message'));
19+
assert.ok(p.status === 134 || p.signal === 'SIGABRT');
Collapse file

‎test/node-api/test_fatal/test_fatal.c‎

Copy file name to clipboardExpand all lines: test/node-api/test_fatal/test_fatal.c
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
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>
17
#include <node_api.h>
28
#include "../../js-native-api/common.h"
39

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+
417
static napi_value Test(napi_env env, napi_callback_info info) {
518
napi_fatal_error("test_fatal::Test", NAPI_AUTO_LENGTH,
619
"fatal message", NAPI_AUTO_LENGTH);
720
return NULL;
821
}
922

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+
1030
static napi_value TestStringLength(napi_env env, napi_callback_info info) {
1131
napi_fatal_error("test_fatal::TestStringLength", 16, "fatal message", 13);
1232
return NULL;
@@ -16,6 +36,7 @@ static napi_value Init(napi_env env, napi_value exports) {
1636
napi_property_descriptor properties[] = {
1737
DECLARE_NODE_API_PROPERTY("Test", Test),
1838
DECLARE_NODE_API_PROPERTY("TestStringLength", TestStringLength),
39+
DECLARE_NODE_API_PROPERTY("TestThread", TestThread),
1940
};
2041

2142
NODE_API_CALL(env, napi_define_properties(
Collapse file

‎test/node-api/test_fatal/test_threads.js‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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');

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.