Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7e4d5f

Browse filesBrowse files
committed
src: shutdown libuv before exit()
This ensures that no operations will be running on the libuv threadpool, which is important because they may run into race conditions with the global destructors being triggered from `exit()`, such as in the added test example here. PR-URL: #35021 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 5e9f0cf commit b7e4d5f
Copy full SHA for b7e4d5f

File tree

Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Open diff view settings
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
@@ -714,6 +714,7 @@ ThreadId AllocateEnvironmentThreadId() {
714714
void DefaultProcessExitHandler(Environment* env, int exit_code) {
715715
Stop(env);
716716
DisposePlatform();
717+
uv_library_shutdown();
717718
exit(exit_code);
718719
}
719720

Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto) { common.skip('missing crypto'); }
4+
const assert = require('assert');
5+
const { generateKeyPair } = require('crypto');
6+
7+
if (common.isWindows) {
8+
// Remove this conditional once the libuv change is in Node.js.
9+
common.skip('crashing due to https://github.com/libuv/libuv/pull/2983');
10+
}
11+
12+
// Regression test for a race condition: process.exit() might lead to OpenSSL
13+
// cleaning up state from the exit() call via calling its destructor, but
14+
// running OpenSSL operations on another thread might lead to them attempting
15+
// to initialize OpenSSL, leading to a crash.
16+
// This test crashed consistently on x64 Linux on Node v14.9.0.
17+
18+
generateKeyPair('rsa', {
19+
modulusLength: 2048,
20+
privateKeyEncoding: {
21+
type: 'pkcs1',
22+
format: 'pem'
23+
}
24+
}, (err/* , publicKey, privateKey */) => {
25+
assert.ifError(err);
26+
});
27+
28+
setTimeout(() => process.exit(), common.platformTimeout(10));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.