Skip to content

Commit 1762f52

Browse files
lingbinamitkdutta
authored andcommitted
[native] Fix incorrect initialization of 'folly::Promise' object
Fixes prestodb#26094 For a `folly::Promise` object that is expected to be overwritten, we should use `folly::makeEmpty()` to initialize it (it is 'invalid') instead of the default constructor (it will be 'valid' but 'not fulfilled', assigning to it will cause an exception). Creating an exception triggers a stack unwind, which can saturate the CPU in high-concurrency scenarios, causing significant performance issues. We don't need to create a new Promise and destruct the previous one in the `ResponseHandler::initialize()` function because `ResponseHandler` isn't supposed to be reused. Therefore, we can simplify the `ResponseHandler::initialize` method.
1 parent 86ad402 commit 1762f52

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

presto-native-execution/presto_cpp/main/http/HttpClient.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ class ResponseHandler : public proxygen::HTTPTransactionHandler {
197197
folly::SemiFuture<std::unique_ptr<HttpResponse>> initialize(
198198
std::shared_ptr<ResponseHandler> self) {
199199
self_ = self;
200-
auto [promise, future] =
201-
folly::makePromiseContract<std::unique_ptr<HttpResponse>>();
202-
promise_ = std::move(promise);
203-
return std::move(future);
200+
return promise_.getSemiFuture();
204201
}
205202

206203
void setTransaction(proxygen::HTTPTransaction* /* txn */) noexcept override {}

0 commit comments

Comments
 (0)