Skip to content

Commit 2dffdbf

Browse files
committed
src: do not register OpenSSL's atexit() handler
Now that crypto no longer initializes OpenSSL from a static initalizer (see previous commit), nothing requires OpenSSL to be torn down at process exit. As mentioned in an earlier commit, `atexit` is expensive, so we now once again avoid it. Signed-off-by: Aviv Keller <me@aviv.sh>
1 parent a1ba046 commit 2dffdbf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/node.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,14 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
12241224
OPENSSL_INIT_set_config_file_flags(settings,
12251225
CONF_MFLAGS_IGNORE_MISSING_FILE);
12261226

1227-
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, settings);
1227+
// OPENSSL_INIT_NO_ATEXIT: do not let OpenSSL register OPENSSL_cleanup()
1228+
// with atexit(). Nothing needs OpenSSL to be torn down when the process
1229+
// exits, and on macOS atexit() itself is expensive: it calls dladdr(),
1230+
// which linearly scans the executable's (very large) symbol table and
1231+
// costs about a millisecond on every process start. This must be part of
1232+
// the first OPENSSL_init_crypto() call in the process to take effect.
1233+
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG | OPENSSL_INIT_NO_ATEXIT,
1234+
settings);
12281235
OPENSSL_INIT_free(settings);
12291236

12301237
if (ERR_peek_error() != 0) {

0 commit comments

Comments
 (0)