Move OpenSSL uninitialization to a separate function
authorJoel Goguen <jgoguen@fb.com>
Wed, 1 Apr 2015 15:11:44 +0000 (08:11 -0700)
committerafrind <afrind@fb.com>
Thu, 2 Apr 2015 19:02:01 +0000 (12:02 -0700)
Summary:
The current behaviour of SSLContext is subject to a bug where an instance going
out of scope at the wrong time can decrement the global refcount to 0, causing
the destructor to destroy the SSL context. Instead, this requires callers to
explicitly uninitialize the SSLContext instance and assume the risk of wrongly
destroying the global SSL context.

Test Plan:
Tested with mcrouter

Reviewed By: subodh@fb.com

Subscribers: afrind, ssl-diffs@, folly-diffs@, yfeldblum, chalfant, dihde, melitam

FB internal diff: D1949649

Tasks: 6358211

Signature: t1:1949649:1427854689:aea2dc801f63256ff64188b0f7a15121dcecee69

folly/io/async/SSLContext.cpp
folly/io/async/SSLContext.h

index 895e7a398a6d782ede8944775966661b9fc40e8b..c05fe330f9a0a95c8f264950cb712e987c8f371e 100644 (file)
@@ -40,17 +40,10 @@ std::mutex    SSLContext::mutex_;
 int SSLContext::sNextProtocolsExDataIndex_ = -1;
 #endif
 
-#ifndef SSLCONTEXT_NO_REFCOUNT
-uint64_t SSLContext::count_ = 0;
-#endif
-
 // SSLContext implementation
 SSLContext::SSLContext(SSLVersion version) {
   {
     std::lock_guard<std::mutex> g(mutex_);
-#ifndef SSLCONTEXT_NO_REFCOUNT
-    count_++;
-#endif
     initializeOpenSSLLocked();
   }
 
@@ -93,15 +86,6 @@ SSLContext::~SSLContext() {
 #ifdef OPENSSL_NPN_NEGOTIATED
   deleteNextProtocolsStrings();
 #endif
-
-#ifndef SSLCONTEXT_NO_REFCOUNT
-  {
-    std::lock_guard<std::mutex> g(mutex_);
-    if (!--count_) {
-      cleanupOpenSSLLocked();
-    }
-  }
-#endif
 }
 
 void SSLContext::ciphers(const std::string& ciphers) {
index 3cabea22941763b61904944aab62f3e06fed3c6e..6947ac7f739dd5180fc80df80e3ddddddfb7c14f 100644 (file)
@@ -425,10 +425,6 @@ class SSLContext {
   static std::mutex mutex_;
   static bool initialized_;
 
-#ifndef SSLCONTEXT_NO_REFCOUNT
-  static uint64_t count_;
-#endif
-
 #ifdef OPENSSL_NPN_NEGOTIATED
   /**
    * Wire-format list of advertised protocols for use in NPN.