From f02900e4978768a8fdc2f53eb2d0d72868743310 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Tue, 26 Aug 2025 11:02:39 +0100 Subject: [PATCH] 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. --- src/api/environment.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/api/environment.cc b/src/api/environment.cc index 0774e810746619..8b0b610393b829 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -1,4 +1,7 @@ #include +#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); }