Commit 5e2ab64f authored by Alan Frindell's avatar Alan Frindell Committed by Facebook GitHub Bot

Fix SSL exception slicing

Summary:
SSLException derives from AsyncSocketException, so need to construct the exception_wrapper differently to prevent slicing it.

I wish there were a more future-proof way to do this

Reviewed By: yangchi

Differential Revision: D29836520

fbshipit-source-id: df4222d94952c66b4c86f12861b3792babdce3c6
parent 832f135a
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <functional> #include <functional>
#include <folly/experimental/coro/Baton.h> #include <folly/experimental/coro/Baton.h>
#include <folly/io/async/ssl/SSLErrors.h>
#include <folly/io/coro/Transport.h> #include <folly/io/coro/Transport.h>
#if FOLLY_HAS_COROUTINES #if FOLLY_HAS_COROUTINES
...@@ -71,6 +72,15 @@ class CallbackBase { ...@@ -71,6 +72,15 @@ class CallbackBase {
// to wrap AsyncTransport errors // to wrap AsyncTransport errors
folly::exception_wrapper error_; folly::exception_wrapper error_;
void storeException(const folly::AsyncSocketException& ex) {
auto sslErr = dynamic_cast<const folly::SSLException*>(&ex);
if (sslErr) {
error_ = folly::make_exception_wrapper<folly::SSLException>(*sslErr);
} else {
error_ = folly::make_exception_wrapper<folly::AsyncSocketException>(ex);
}
}
private: private:
virtual void cancel() noexcept = 0; virtual void cancel() noexcept = 0;
}; };
...@@ -91,7 +101,7 @@ class ConnectCallback : public CallbackBase, ...@@ -91,7 +101,7 @@ class ConnectCallback : public CallbackBase,
void connectSuccess() noexcept override { post(); } void connectSuccess() noexcept override { post(); }
void connectErr(const folly::AsyncSocketException& ex) noexcept override { void connectErr(const folly::AsyncSocketException& ex) noexcept override {
error_ = folly::exception_wrapper(ex); storeException(ex);
post(); post();
} }
folly::AsyncSocket& socket_; folly::AsyncSocket& socket_;
...@@ -199,7 +209,7 @@ class ReadCallback : public CallbackBase, ...@@ -199,7 +209,7 @@ class ReadCallback : public CallbackBase,
// disable callbacks // disable callbacks
transport_.setReadCB(nullptr); transport_.setReadCB(nullptr);
cancelTimeout(); cancelTimeout();
error_ = folly::exception_wrapper(ex); storeException(ex);
post(); post();
} }
...@@ -217,8 +227,8 @@ class ReadCallback : public CallbackBase, ...@@ -217,8 +227,8 @@ class ReadCallback : public CallbackBase,
// If the timeout fires but this ReadCallback did get some data, ignore it. // If the timeout fires but this ReadCallback did get some data, ignore it.
// post() has already happend from readDataAvailable. // post() has already happend from readDataAvailable.
if (length == 0) { if (length == 0) {
error_ = folly::exception_wrapper(folly::AsyncSocketException( error_ = folly::make_exception_wrapper<folly::AsyncSocketException>(
Error::TIMED_OUT, "Timed out waiting for data", errno)); Error::TIMED_OUT, "Timed out waiting for data", errno);
post(); post();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment