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 @@
#include <functional>
#include <folly/experimental/coro/Baton.h>
#include <folly/io/async/ssl/SSLErrors.h>
#include <folly/io/coro/Transport.h>
#if FOLLY_HAS_COROUTINES
......@@ -71,6 +72,15 @@ class CallbackBase {
// to wrap AsyncTransport errors
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:
virtual void cancel() noexcept = 0;
};
......@@ -91,7 +101,7 @@ class ConnectCallback : public CallbackBase,
void connectSuccess() noexcept override { post(); }
void connectErr(const folly::AsyncSocketException& ex) noexcept override {
error_ = folly::exception_wrapper(ex);
storeException(ex);
post();
}
folly::AsyncSocket& socket_;
......@@ -199,7 +209,7 @@ class ReadCallback : public CallbackBase,
// disable callbacks
transport_.setReadCB(nullptr);
cancelTimeout();
error_ = folly::exception_wrapper(ex);
storeException(ex);
post();
}
......@@ -217,8 +227,8 @@ class ReadCallback : public CallbackBase,
// If the timeout fires but this ReadCallback did get some data, ignore it.
// post() has already happend from readDataAvailable.
if (length == 0) {
error_ = folly::exception_wrapper(folly::AsyncSocketException(
Error::TIMED_OUT, "Timed out waiting for data", errno));
error_ = folly::make_exception_wrapper<folly::AsyncSocketException>(
Error::TIMED_OUT, "Timed out waiting for data", errno);
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