Skip to content

Commit f983561

Browse files
Fuat Gelerifacebook-github-bot
authored andcommitted
Fix exception slicing error when converting exception to exception_wrapper
Summary: Passing the const& of an exception to the exception_wrapper causes slicing error, if the error is extending std::runtime_error. Which was the case for this bug. So, creating an exception_ptr and providing that along with the pure object solves the issue. Reviewed By: William-J-Earl Differential Revision: D9829021 fbshipit-source-id: 257d457f9ccf500fa7a15b20d2eb5f2c999bea3a
1 parent f2ebb55 commit f983561

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

rsocket/test/transport/TcpDuplexConnectionTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <folly/futures/Future.h>
1616
#include <folly/io/async/AsyncTransport.h>
1717
#include <folly/io/async/ScopedEventBaseThread.h>
18+
#include <folly/io/async/ssl/SSLErrors.h>
1819
#include <gtest/gtest.h>
1920

2021
#include "rsocket/test/transport/DuplexConnectionTest.h"
@@ -109,5 +110,25 @@ TEST(TcpDuplexConnection, ConnectionAndSubscribersAreUntied) {
109110
worker.getEventBase());
110111
}
111112

113+
TEST(TcpDuplexConnection, ExceptionWrapperTest) {
114+
folly::AsyncSocketException socketException(
115+
folly::AsyncSocketException::AsyncSocketExceptionType::INVALID_STATE,
116+
"test",
117+
10);
118+
folly::SSLException sslException(5, 10, 15, 20);
119+
120+
const folly::AsyncSocketException& socketExceptionRef = sslException;
121+
122+
folly::exception_wrapper ex1(socketException);
123+
folly::exception_wrapper ex2(sslException);
124+
125+
// Slicing error:
126+
// folly::exception_wrapper ex3(socketExceptionRef);
127+
128+
// Fixed version:
129+
folly::exception_wrapper ex3(
130+
std::make_exception_ptr(socketExceptionRef), socketExceptionRef);
131+
}
132+
112133
} // namespace tests
113134
} // namespace rsocket

rsocket/transports/tcp/TcpDuplexConnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TcpReaderWriter : public folly::AsyncTransportWrapper::WriteCallback,
110110
void writeErr(
111111
size_t,
112112
const folly::AsyncSocketException& exn) noexcept override {
113-
closeErr(folly::exception_wrapper{exn});
113+
closeErr(folly::exception_wrapper{std::make_exception_ptr(exn), exn});
114114
intrusive_ptr_release(this);
115115
}
116116

@@ -135,7 +135,7 @@ class TcpReaderWriter : public folly::AsyncTransportWrapper::WriteCallback,
135135
}
136136

137137
void readErr(const folly::AsyncSocketException& exn) noexcept override {
138-
closeErr(exn);
138+
closeErr(folly::exception_wrapper{std::make_exception_ptr(exn), exn});
139139
intrusive_ptr_release(this);
140140
}
141141

0 commit comments

Comments
 (0)