diff --git a/src/node_crypto.cc b/src/node_crypto.cc index de2545f3859970..8fac840244c6f7 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5126,6 +5126,8 @@ void InitCryptoOnce() { ERR_load_ENGINE_strings(); ENGINE_load_builtin_engines(); #endif // !OPENSSL_NO_ENGINE + + NodeBIO::GetMethod(); } diff --git a/src/node_crypto.h b/src/node_crypto.h index ee069c9cf799b2..269bccbc03a1d7 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -97,6 +97,8 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx); extern void UseExtraCaCerts(const std::string& file); +void InitCryptoOnce(); + class SecureContext : public BaseObject { public: ~SecureContext() override { diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc index ab68c0a08111f2..baa90204f2f97a 100644 --- a/src/node_crypto_bio.cc +++ b/src/node_crypto_bio.cc @@ -247,6 +247,8 @@ const BIO_METHOD* NodeBIO::GetMethod() { return &method; #else + // This is called from InitCryptoOnce() to avoid race conditions during + // initialization. static BIO_METHOD* method = nullptr; if (method == nullptr) { diff --git a/src/node_crypto_bio.h b/src/node_crypto_bio.h index fefd097b32a7ba..0c61f19d0189d2 100644 --- a/src/node_crypto_bio.h +++ b/src/node_crypto_bio.h @@ -164,6 +164,8 @@ class NodeBIO : public MemoryRetainer { int eof_return_ = -1; Buffer* read_head_ = nullptr; Buffer* write_head_ = nullptr; + + friend void node::crypto::InitCryptoOnce(); }; } // namespace crypto