diff --git a/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp b/presto-native-execution/presto_cpp/main/tests/PrestoQueryRunner.cpp index a4e2da62db8b..3ac0b05278a6 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; }