Skip to content

Commit 1d7aa91

Browse files
authored
Add a re-entrancy guard to exitRuntime() (#26838)
Add a re-entrancy guard to exitRuntime(), since such re-entrancy is seen to happen if an atexit() handler throws a JS exception (e.g. RuntimeError: index out of bounds) Separated out from #26835.
1 parent abf9a60 commit 1d7aa91

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/preamble.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@ function preMain() {
188188
#endif
189189

190190
#if EXIT_RUNTIME
191+
192+
#if ASSERTIONS
193+
var runtimeExiting = false;
194+
#endif
195+
191196
function exitRuntime() {
192197
#if RUNTIME_DEBUG
193198
dbg('exitRuntime');
194199
#endif
195200
#if ASSERTIONS
196201
assert(!runtimeExited);
202+
assert(!runtimeExiting, 'Re-entrant call to exitRuntime()! This can happen if an atexit() registered callback throws an exception.');
203+
runtimeExiting = true;
197204
#endif
198205
#if ASYNCIFY == 1 && ASSERTIONS
199206
// ASYNCIFY cannot be used once the runtime starts shutting down.

0 commit comments

Comments
 (0)