From af570d3b178f6c61a31952dd4abdb8e6f918433f Mon Sep 17 00:00:00 2001 From: Jimmy Lu Date: Thu, 16 Nov 2023 07:56:58 -0800 Subject: [PATCH] [native] Fix PrestoQueryRunner in case query fails 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`. --- .../presto_cpp/main/tests/PrestoQueryRunner.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp b/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp index a4e2da62db8b3..3ac0b05278a6b 100644 --- a/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp +++ b/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp @@ -462,6 +462,11 @@ std::multiset> PrestoQueryRunner::execute( std::vector PrestoQueryRunner::execute(const std::string& sql) { auto sessionPool = std::make_unique(); + SCOPE_EXIT { + eventBaseThread_.getEventBase()->runInEventBaseThread( + [sessionPool = std::move(sessionPool)] {}); + }; + auto client = std::make_shared( eventBaseThread_.getEventBase(), sessionPool.get(), @@ -488,9 +493,6 @@ std::vector PrestoQueryRunner::execute(const std::string& sql) { response = ServerResponse(fetchNext(response.nextUri(), *client)); response.throwIfFailed(); } - - eventBaseThread_.getEventBase()->runInEventBaseThread( - [sessionPool = std::move(sessionPool)] {}); return queryResults; }