Skip to content

Commit b1d0a11

Browse files
Alex Zhavnerchikfacebook-github-bot
authored andcommitted
Fix a bug in how ScopedServerInterfaceThread creates clients
Summary: TLRD: Before this change trying to use ScopedServerInterfaceThread::newClient() to create client using binary protocol would crash the process. ScopedServerInterfaceThread::newChannel takes executor, channel functor, numThreads and protocol. The thing is ScopedServerInterfaceThread::newClient calls are passing protocol in place of numThreads. Because protocol is just an enum (not enum class), it is implicitly converted into int and default protocol T_BINARY_PROTOCOL is used instead of T_COMPACT_PROTOCOL that is default for ScopedServerInterfaceThread::newClient. This worked only because T_COMPACT_PROTOCOL is when implicitly converted to int results in value of 2 for numThreads. But, if one tries to actually create client with T_BINARY_PROTOCOL who's int value is 0, the process crashes with devision by 0. Reviewed By: owwlo Differential Revision: D75345838 fbshipit-source-id: 19253c61a22299e0a2ff44de6b49a11ec620d843
1 parent 289ea30 commit b1d0a11

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

third-party/thrift/src/thrift/lib/cpp2/test/util/ScopedServerInterfaceThreadTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ TEST(ScopedServerInterfaceThread, newClient) {
114114
EXPECT_EQ(6, cli->sync_add(-3, 9));
115115
}
116116

117+
TEST(ScopedServerInterfaceThread, newClientBinary) {
118+
ScopedServerInterfaceThread ssit(make_shared<SimpleServiceImpl>());
119+
120+
EventBase eb;
121+
auto cli = ssit.newClient<SimpleServiceAsyncClient>(
122+
&eb, RocketClientChannel::newChannel, protocol::T_BINARY_PROTOCOL);
123+
124+
EXPECT_EQ(6, cli->sync_add(-3, 9));
125+
}
126+
117127
TEST(ScopedServerInterfaceThread, newClient_SemiFuture) {
118128
ScopedServerInterfaceThread ssit(make_shared<SimpleServiceImpl>());
119129

third-party/thrift/src/thrift/lib/cpp2/transport/rocket/framing/parser/test/AlignedParserStrategyTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ TEST(AlignedParserStrategyTest, TestAlignmentWithRPC) {
496496
auto handler = std::make_shared<TestServiceHandler>();
497497
auto server =
498498
std::make_shared<ScopedServerInterfaceThread>(handler, [](auto&) {});
499-
auto client = server->newClient<apache::thrift::Client<TestService>>();
499+
auto client = server->newClient<apache::thrift::Client<TestService>>(
500+
nullptr, RocketClientChannel::newChannel, protocol::T_BINARY_PROTOCOL);
500501

501502
for (int i = 0; i < 20; ++i) {
502503
{

third-party/thrift/src/thrift/lib/cpp2/util/ScopedServerInterfaceThread-inl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ std::unique_ptr<AsyncClientT> ScopedServerInterfaceThread::newClient(
232232
folly::Executor* callbackExecutor,
233233
ScopedServerInterfaceThread::MakeChannelFunc makeChannel,
234234
protocol::PROTOCOL_TYPES prot) const {
235-
return std::make_unique<AsyncClientT>(
236-
newChannel(callbackExecutor, std::move(makeChannel), prot));
235+
return std::make_unique<AsyncClientT>(newChannel(
236+
callbackExecutor,
237+
std::move(makeChannel),
238+
folly::hardware_concurrency(),
239+
prot));
237240
}
238241

239242
template <class AsyncClientT>

0 commit comments

Comments
 (0)