Skip to content

Commit

Permalink
[native] Fix PrestoQueryRunner in case query fails
Browse files Browse the repository at this point in the history
In case the query fails, `PrestoQueryRunner::execute` throws an exception.  This
triggers the destructor of `SessionPool` to be called in current thread instead
of the event loop thread.  Fix this by wrapping the ownership transfer inside
`SCOPE_EXIT`.
  • Loading branch information
Yuhta authored and mbasmanova committed Nov 16, 2023
1 parent c1f7fc7 commit 6bcf330
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ std::multiset<std::vector<variant>> PrestoQueryRunner::execute(

std::vector<RowVectorPtr> PrestoQueryRunner::execute(const std::string& sql) {
auto sessionPool = std::make_unique<proxygen::SessionPool>();
SCOPE_EXIT {
eventBaseThread_.getEventBase()->runInEventBaseThread(
[sessionPool = std::move(sessionPool)] {});
};

auto client = std::make_shared<http::HttpClient>(
eventBaseThread_.getEventBase(),
sessionPool.get(),
Expand All @@ -488,9 +493,6 @@ std::vector<RowVectorPtr> PrestoQueryRunner::execute(const std::string& sql) {
response = ServerResponse(fetchNext(response.nextUri(), *client));
response.throwIfFailed();
}

eventBaseThread_.getEventBase()->runInEventBaseThread(
[sessionPool = std::move(sessionPool)] {});
return queryResults;
}

Expand Down

0 comments on commit 6bcf330

Please sign in to comment.