Commit ba2e341
n-api: run all finalizers via SetImmediate()
Throwing an exception from a finalizer can cause the following fatal
error:
Error: async hook stack has become corrupted (actual: 2, expected: 0)
1: 0x970b5a node::InternalCallbackScope::~InternalCallbackScope()
[./node]
2: 0x99dda0 node::Environment::RunTimers(uv_timer_s*) [./node]
3: 0x13d8b22 [./node]
4: 0x13dbe42 uv_run [./node]
5: 0xa57974 node::NodeMainInstance::Run() [./node]
6: 0x9dbc17 node::Start(int, char**) [./node]
7: 0x7f4965417f43 __libc_start_main [/lib64/libc.so.6]
8: 0x96f4ae _start [./node]
By #34341 (comment),
calling into JS from a finalizer and/or throwing exceptions from there
is not advised, because the stack may or may not be set up for JS
execution. The best solution is to run the user's finalizer from a
`SetImmediate()` callback.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
Fixes: #34341
PR-URL: #34386
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>1 parent afd6e46 commit ba2e341Copy full SHA for ba2e341
File tree
Expand file treeCollapse file tree
12 files changed
+200
-163
lines changedOpen diff view settings
Filter options
- benchmark/napi/ref
- src
- test
- common
- js-native-api
- 7_factory_wrap
- 8_passing_wrapped
- test_exception
- test_general
- test_reference
Expand file treeCollapse file tree
12 files changed
+200
-163
lines changedOpen diff view settings
Collapse file
benchmark/napi/ref/index.js
Copy file name to clipboardExpand all lines: benchmark/napi/ref/index.js+6-4Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
10 | 10 | |
11 | 11 | |
12 | 12 | |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
17 | 19 | |
Collapse file
+1-7Lines changed: 1 addition & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
267 | 267 | |
268 | 268 | |
269 | 269 | |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
| 270 | + |
277 | 271 | |
278 | 272 | |
279 | 273 | |
|
Collapse file
+7Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
101 | 101 | |
102 | 102 | |
103 | 103 | |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
104 | 111 | |
105 | 112 | |
106 | 113 | |
|
Collapse file
+11Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
32 | 32 | |
33 | 33 | |
34 | 34 | |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
35 | 46 | |
36 | 47 | |
37 | 48 | |
|
Collapse file
+25Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
675 | 675 | |
676 | 676 | |
677 | 677 | |
| 678 | + |
| 679 | + |
| 680 | + |
| 681 | + |
| 682 | + |
| 683 | + |
| 684 | + |
| 685 | + |
| 686 | + |
| 687 | + |
| 688 | + |
| 689 | + |
| 690 | + |
| 691 | + |
| 692 | + |
| 693 | + |
| 694 | + |
| 695 | + |
| 696 | + |
| 697 | + |
| 698 | + |
| 699 | + |
| 700 | + |
| 701 | + |
678 | 702 | |
679 | 703 | |
680 | 704 | |
| ||
685 | 709 | |
686 | 710 | |
687 | 711 | |
| 712 | + |
688 | 713 | |
689 | 714 | |
690 | 715 | |
|
Collapse file
test/js-native-api/7_factory_wrap/test.js
Copy file name to clipboardExpand all lines: test/js-native-api/7_factory_wrap/test.js+17-16Lines changed: 17 additions & 16 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
6 | 6 | |
7 | 7 | |
8 | 8 | |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
17 | 17 | |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
Collapse file
test/js-native-api/8_passing_wrapped/test.js
Copy file name to clipboardExpand all lines: test/js-native-api/8_passing_wrapped/test.js+12-9Lines changed: 12 additions & 9 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
5 | 5 | |
6 | 6 | |
7 | 7 | |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
12 | 13 | |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
Collapse file
test/js-native-api/test_exception/test.js
Copy file name to clipboardExpand all lines: test/js-native-api/test_exception/test.js-11Lines changed: 0 additions & 11 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
66 | 66 | |
67 | 67 | |
68 | 68 | |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
Collapse file
test/js-native-api/test_exception/testFinalizerException.js
Copy file name to clipboard+32Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
Collapse file
test/js-native-api/test_general/test.js
Copy file name to clipboardExpand all lines: test/js-native-api/test_general/test.js+26-26Lines changed: 26 additions & 26 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - |
66 | | - |
67 | 54 | |
68 | 55 | |
69 | 56 | |
70 | 57 | |
71 | 58 | |
| 59 | + |
| 60 | + |
72 | 61 | |
73 | 62 | |
74 | 63 | |
75 | 64 | |
76 | 65 | |
77 | 66 | |
78 | 67 | |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
| 68 | + |
| 69 | + |
92 | 70 | |
93 | 71 | |
94 | 72 | |
95 | 73 | |
96 | 74 | |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
0 commit comments