src: fix race on process exit and off thread CA loading

When calling `process.exit()` or on uncaught exceptions as soon as the
process starts, the process will try to terminate immediately. In this
case, there could be a race condition on the unfinished off-thread
system CA loader which tries to access the OpenSSL API which has been
de-inited on the main thread.

PR-URL: https://github.com/nodejs/node/pull/59632
Refs: https://github.com/nodejs/node/pull/59550
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Chengzhong Wu
2025-09-02 11:19:25 +01:00
committed by GitHub
parent 961554c89d
commit 737b42e4ee

View File

@@ -1,4 +1,7 @@
#include <cstdlib>
#if HAVE_OPENSSL
#include "crypto/crypto_util.h"
#endif // HAVE_OPENSSL
#include "env_properties.h"
#include "node.h"
#include "node_builtins.h"
@@ -1004,6 +1007,11 @@ void DefaultProcessExitHandlerInternal(Environment* env, ExitCode exit_code) {
// in node_v8_platform-inl.h
uv_library_shutdown();
DisposePlatform();
#if HAVE_OPENSSL
crypto::CleanupCachedRootCertificates();
#endif // HAVE_OPENSSL
Exit(exit_code);
}