Skip to content

Commit 37ce137

Browse files
iahsfacebook-github-bot
authored andcommitted
Use RAII to manage tile refcount
Summary: The complexity of the ownership model has scaled with the number of new features, leaving room for edgecases to slip in. Using move-only guards will ensure we never leak resources. Differential Revision: D28611867 fbshipit-source-id: c5d4a8155ad0b50e537dddc8f07f389afd490bdf
1 parent 7786160 commit 37ce137

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

yarpl/flowable/ThriftStreamShim.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,11 @@ class ThriftStreamShim {
156156
StreamServerCallbackAdaptor(
157157
folly::Try<apache::thrift::StreamPayload> (*encode)(folly::Try<T>&&),
158158
folly::EventBase* eb,
159-
apache::thrift::Tile* interaction)
160-
: encode_(encode), eb_(eb), interaction_(interaction) {}
161-
~StreamServerCallbackAdaptor() {
162-
if (interaction_) {
163-
std::move(eb_).add([interaction = interaction_](auto eb) {
164-
interaction->__fbthrift_releaseRef(
165-
*eb, apache::thrift::InteractionReleaseEvent::STREAM_END);
166-
});
167-
}
168-
}
159+
apache::thrift::TilePtr&& interaction)
160+
: encode_(encode),
161+
eb_(eb),
162+
interaction_(apache::thrift::TileStreamGuard::transferFrom(
163+
std::move(interaction))) {}
169164
// StreamServerCallback implementation
170165
bool onStreamRequestN(uint64_t tokens) override {
171166
if (!subscription_) {
@@ -241,7 +236,7 @@ class ThriftStreamShim {
241236
folly::Try<apache::thrift::StreamPayload> (*encode_)(folly::Try<T>&&);
242237
folly::Executor::KeepAlive<folly::EventBase> eb_;
243238
std::shared_ptr<StreamServerCallbackAdaptor> self_;
244-
apache::thrift::Tile* interaction_;
239+
apache::thrift::TileStreamGuard interaction_;
245240
};
246241

247242
return apache::thrift::ServerStream<T>(
@@ -254,9 +249,9 @@ class ThriftStreamShim {
254249
apache::thrift::FirstResponsePayload&& payload,
255250
apache::thrift::StreamClientCallback* callback,
256251
folly::EventBase* clientEb,
257-
apache::thrift::Tile* interaction) mutable {
252+
apache::thrift::TilePtr&& interaction) mutable {
258253
auto stream = std::make_shared<StreamServerCallbackAdaptor>(
259-
encode, clientEb, interaction);
254+
encode, clientEb, std::move(interaction));
260255
stream->takeRef(stream);
261256
stream->resetClientCallback(*callback);
262257
std::ignore = callback->onFirstResponse(

0 commit comments

Comments
 (0)