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 cb scope bugs involved in termination · nodejs/node@03e8d82

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/api
    • callback.cc
    • environment.cc
  • test/parallel
    • test-unhandled-exception-with-worker-inuse.js
    • test-worker-http2-stream-terminate.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/api/callback.cc‎

Copy file name to clipboardExpand all lines: src/api/callback.cc
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ void InternalCallbackScope::Close() {
9797
if (closed_) return;
9898
closed_ = true;
9999

100-
Isolate* isolate = env_->isolate();
101-
auto idle = OnScopeLeave([&]() { isolate->SetIdle(true); });
100+
// This function must ends up with either cleanup the
101+
// async id stack or pop the topmost one from it
102102

103-
if (!env_->can_call_into_js()) return;
104103
auto perform_stopping_check = [&]() {
105104
if (env_->is_stopping()) {
106105
MarkAsFailed();
@@ -109,6 +108,11 @@ void InternalCallbackScope::Close() {
109108
};
110109
perform_stopping_check();
111110

111+
if (env_->is_stopping()) return;
112+
113+
Isolate* isolate = env_->isolate();
114+
auto idle = OnScopeLeave([&]() { isolate->SetIdle(true); });
115+
112116
if (!failed_ && async_context_.async_id != 0 && !skip_hooks_) {
113117
AsyncWrap::EmitAfter(env_, async_context_.async_id);
114118
}
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ ThreadId AllocateEnvironmentThreadId() {
802802
}
803803

804804
void DefaultProcessExitHandler(Environment* env, int exit_code) {
805+
env->set_stopping(true);
805806
env->set_can_call_into_js(false);
806807
env->stop_sub_worker_contexts();
807808
env->isolate()->DumpAndResetStats();
Collapse file

‎test/parallel/test-unhandled-exception-with-worker-inuse.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// https://github.com/nodejs/node/issues/45421
5+
//
6+
// Check that node will NOT call v8::Isolate::SetIdle() when exiting
7+
// due to an unhandled exception, otherwise the assertion(enabled in
8+
// debug build only) in the SetIdle(), which checks that the vm state
9+
// is either EXTERNAL or IDLE will fail.
10+
//
11+
// The root cause of this issue is that before PerIsolateMessageListener()
12+
// is invoked by v8, v8 preserves the JS vm state, although it should
13+
// switch to EXTERNEL. https://bugs.chromium.org/p/v8/issues/detail?id=13464
14+
//
15+
// Therefore, this commit can be considered as an workaround of the v8 bug,
16+
// but we also find it not useful to call SetIdle() when terminating.
17+
18+
if (process.argv[2] === 'child') {
19+
const { Worker } = require('worker_threads');
20+
new Worker('', { eval: true });
21+
throw new Error('xxx');
22+
} else {
23+
const assert = require('assert');
24+
const { spawnSync } = require('child_process');
25+
const result = spawnSync(process.execPath, [__filename, 'child']);
26+
27+
const stderr = result.stderr.toString().trim();
28+
// Expect error message to be preserved
29+
assert.match(stderr, /xxx/);
30+
// Expect no crash
31+
assert(!common.nodeProcessAborted(result.status, result.signal), stderr);
32+
}
Collapse file

‎…al/test-worker-http2-stream-terminate.js‎ ‎…el/test-worker-http2-stream-terminate.js‎test/sequential/test-worker-http2-stream-terminate.js renamed to test/parallel/test-worker-http2-stream-terminate.js test/sequential/test-worker-http2-stream-terminate.js renamed to test/parallel/test-worker-http2-stream-terminate.js

Copy file name to clipboard
File renamed without changes.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — 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.