You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/01/14 00:21:46 UTC

[3/3] mesos git commit: Fixed SSL socket 'shutdown()'.

Fixed SSL socket 'shutdown()'.

Recently, a change was made to the signature of
`Socket::shutdown`, but the corresponding override in
`LibeventSSLSocketImpl` was not updated, so that the
implementation-specific method is no longer being
executed. Further, the SSL socket's `shutdown` code
did not actually shutdown the socket; rather, the
shutdown was performed in the destructor.

This patch updates the function's signature to match
that of the base class's method, adds the `override`
specifier to the implemention's method declaration,
and updates the function to properly shutdown the
SSL socket.

Review: https://reviews.apache.org/r/55343/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c600d12a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c600d12a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c600d12a

Branch: refs/heads/master
Commit: c600d12a01865daad8ba7607b53eff35686f0f35
Parents: 5023e00
Author: Greg Mann <gr...@mesosphere.io>
Authored: Fri Jan 13 15:56:34 2017 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Jan 13 16:20:02 2017 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/socket.hpp  |  4 ++--
 3rdparty/libprocess/src/libevent_ssl_socket.cpp | 13 +++++++------
 3rdparty/libprocess/src/libevent_ssl_socket.hpp | 12 ++++++++----
 3 files changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c600d12a/3rdparty/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp
index 8796615..5e958ad 100644
--- a/3rdparty/libprocess/include/process/socket.hpp
+++ b/3rdparty/libprocess/include/process/socket.hpp
@@ -181,8 +181,8 @@ public:
   virtual Future<Nothing> send(const std::string& data);
 
   /**
-   * Shutdown the receive-side of the socket. No further data can be
-   * received from the socket.
+   * Shuts down the socket. Accepts an integer which specifies the
+   * shutdown mode.
    */
   virtual Try<Nothing> shutdown(int how)
   {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c600d12a/3rdparty/libprocess/src/libevent_ssl_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent_ssl_socket.cpp b/3rdparty/libprocess/src/libevent_ssl_socket.cpp
index b0319b2..fec131f 100644
--- a/3rdparty/libprocess/src/libevent_ssl_socket.cpp
+++ b/3rdparty/libprocess/src/libevent_ssl_socket.cpp
@@ -128,14 +128,10 @@ LibeventSSLSocketImpl::~LibeventSSLSocketImpl()
         }
 
         if (_bev != nullptr) {
-          SSL* ssl = bufferevent_openssl_get_ssl(_bev);
-          // Workaround for SSL shutdown, see http://www.wangafu.net/~nickm/libevent-book/Ref6a_advanced_bufferevents.html // NOLINT
-          SSL_set_shutdown(ssl, SSL_RECEIVED_SHUTDOWN);
-          SSL_shutdown(ssl);
-
           // NOTE: Removes all future callbacks using 'this->bev'.
           bufferevent_disable(_bev, EV_READ | EV_WRITE);
 
+          SSL* ssl = bufferevent_openssl_get_ssl(_bev);
           SSL_free(ssl);
           bufferevent_free(_bev);
         }
@@ -154,7 +150,7 @@ void LibeventSSLSocketImpl::initialize()
 }
 
 
-Try<Nothing> LibeventSSLSocketImpl::shutdown()
+Try<Nothing> LibeventSSLSocketImpl::shutdown(int how)
 {
   // Nothing to do if this socket was never initialized.
   synchronized (lock) {
@@ -196,6 +192,11 @@ Try<Nothing> LibeventSSLSocketImpl::shutdown()
             request->promise
               .set(bufferevent_read(self->bev, request->data, request->size));
           }
+
+          // Workaround for SSL shutdown, see http://www.wangafu.net/~nickm/libevent-book/Ref6a_advanced_bufferevents.html // NOLINT
+          SSL* ssl = bufferevent_openssl_get_ssl(self->bev);
+          SSL_set_shutdown(ssl, SSL_RECEIVED_SHUTDOWN);
+          SSL_shutdown(ssl);
         }
       },
       DISALLOW_SHORT_CIRCUIT);

http://git-wip-us.apache.org/repos/asf/mesos/blob/c600d12a/3rdparty/libprocess/src/libevent_ssl_socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent_ssl_socket.hpp b/3rdparty/libprocess/src/libevent_ssl_socket.hpp
index 65da091..97ce339 100644
--- a/3rdparty/libprocess/src/libevent_ssl_socket.hpp
+++ b/3rdparty/libprocess/src/libevent_ssl_socket.hpp
@@ -49,10 +49,14 @@ public:
   virtual Future<std::shared_ptr<SocketImpl>> accept();
   virtual SocketImpl::Kind kind() const { return SocketImpl::Kind::SSL; }
 
-  // This call is used to do the equivalent of shutting down the read
-  // end. This means finishing the future of any outstanding read
-  // request.
-  virtual Try<Nothing> shutdown();
+  // Shuts down the socket.
+  //
+  // NOTE: Although this method accepts an integer which specifies the
+  // shutdown mode, this parameter is ignored because SSL connections
+  // do not have a concept of read/write-only shutdown. If either end
+  // of the socket is closed, then the futures of any outstanding read
+  // requests will be completed (possibly as failures).
+  virtual Try<Nothing> shutdown(int how) override;
 
   // We need a post-initializer because 'shared_from_this()' is not
   // valid until the constructor has finished.