diff --git a/ydb/library/yql/providers/dq/provider/yql_dq_gateway.cpp b/ydb/library/yql/providers/dq/provider/yql_dq_gateway.cpp index a6d15b70ba7e..9c4c0565fbba 100644 --- a/ydb/library/yql/providers/dq/provider/yql_dq_gateway.cpp +++ b/ydb/library/yql/providers/dq/provider/yql_dq_gateway.cpp @@ -526,13 +526,24 @@ class TDqGatewayImpl: public std::enable_shared_from_this { std::shared_ptr session; with_lock(Mutex) { auto it = Sessions.find(sessionId); - if (it == Sessions.end()) { - YQL_CLOG(ERROR, ProviderDq) << "Session was closed: " << sessionId; - return MakeErrorFuture(std::make_exception_ptr(std::runtime_error("Session was closed"))); + if (it != Sessions.end()) { + session = it->second; } - session = it->second; } - return session->ExecutePlan(std::move(plan), columns, secureParams, graphParams, settings, progressWriter, modulesMapping, discard); + if (!session) { + YQL_CLOG(ERROR, ProviderDq) << "Session was closed: " << sessionId; + return MakeFuture(NCommon::ResultFromException(yexception() << "Session was closed")); + } + return session->ExecutePlan(std::move(plan), columns, secureParams, graphParams, settings, progressWriter, modulesMapping, discard) + .Apply([](const TFuture& f) { + try { + f.TryRethrow(); + } catch (const std::exception& e) { + YQL_CLOG(ERROR, ProviderDq) << e.what(); + return MakeFuture(NCommon::ResultFromException(e)); + } + return f; + }); } private: