Merge pull request #3079 from yandex/fix-query-scope

Fixed usage of query scope in TCPHandler #2482
This commit is contained in:
alexey-milovidov 2018-09-08 04:36:45 +03:00 committed by GitHub
commit bd8f1e92c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -213,9 +213,7 @@ void HTTPHandler::processQuery(
Context context = server.context(); Context context = server.context();
context.setGlobalContext(server.context()); context.setGlobalContext(server.context());
/// It will forcibly detach query even if unexpected error ocurred and detachQuery() was not called CurrentThread::QueryScope query_scope(context);
/// Normal detaching is happen in BlockIO callbacks
CurrentThread::QueryScope query_scope_holder(context);
LOG_TRACE(log, "Request URI: " << request.getURI()); LOG_TRACE(log, "Request URI: " << request.getURI());

View File

@ -130,6 +130,9 @@ void TCPHandler::runImpl()
Stopwatch watch; Stopwatch watch;
state.reset(); state.reset();
/// Initialized later.
std::optional<CurrentThread::QueryScope> query_scope;
/** An exception during the execution of request (it must be sent over the network to the client). /** An exception during the execution of request (it must be sent over the network to the client).
* The client will be able to accept it, if it did not happen while sending another packet and the client has not disconnected yet. * The client will be able to accept it, if it did not happen while sending another packet and the client has not disconnected yet.
*/ */
@ -152,7 +155,7 @@ void TCPHandler::runImpl()
if (!receivePacket()) if (!receivePacket())
continue; continue;
CurrentThread::initializeQuery(); query_scope.emplace(query_context);
send_exception_with_stack_trace = query_context.getSettingsRef().calculate_text_stack_trace; send_exception_with_stack_trace = query_context.getSettingsRef().calculate_text_stack_trace;
@ -197,6 +200,8 @@ void TCPHandler::runImpl()
sendLogs(); sendLogs();
sendEndOfStream(); sendEndOfStream();
query_scope.reset();
state.reset(); state.reset();
} }
catch (const Exception & e) catch (const Exception & e)
@ -265,9 +270,7 @@ void TCPHandler::runImpl()
try try
{ {
/// It will forcibly detach query even if unexpected error ocсurred and detachQuery() was not called query_scope.reset();
CurrentThread::detachQueryIfNotDetached();
state.reset(); state.reset();
} }
catch (...) catch (...)