mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 20:02:05 +00:00
Better diagnostics when client has dropped connection
This commit is contained in:
parent
13b8dce792
commit
74558a4e27
@ -277,6 +277,9 @@ void TCPHandler::runImpl()
|
||||
/// Do it before sending end of stream, to have a chance to show log message in client.
|
||||
query_scope->logPeakMemoryUsage();
|
||||
|
||||
if (state.is_connection_closed)
|
||||
break;
|
||||
|
||||
sendLogs();
|
||||
sendEndOfStream();
|
||||
|
||||
@ -444,7 +447,11 @@ bool TCPHandler::readDataNext(const size_t & poll_interval, const int & receive_
|
||||
|
||||
/// If client disconnected.
|
||||
if (in->eof())
|
||||
{
|
||||
LOG_INFO(log, "Client has dropped the connection, cancel the query.");
|
||||
state.is_connection_closed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// We accept and process data. And if they are over, then we leave.
|
||||
if (!receivePacket())
|
||||
@ -477,9 +484,8 @@ void TCPHandler::readData(const Settings & connection_settings)
|
||||
std::tie(poll_interval, receive_timeout) = getReadTimeouts(connection_settings);
|
||||
sendLogs();
|
||||
|
||||
while (true)
|
||||
if (!readDataNext(poll_interval, receive_timeout))
|
||||
return;
|
||||
while (readDataNext(poll_interval, receive_timeout))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@ -567,6 +573,9 @@ void TCPHandler::processOrdinaryQuery()
|
||||
sendProgress();
|
||||
}
|
||||
|
||||
if (state.is_connection_closed)
|
||||
return;
|
||||
|
||||
sendData({});
|
||||
}
|
||||
|
||||
@ -632,6 +641,9 @@ void TCPHandler::processOrdinaryQueryWithProcessors()
|
||||
sendLogs();
|
||||
}
|
||||
|
||||
if (state.is_connection_closed)
|
||||
return;
|
||||
|
||||
sendData({});
|
||||
}
|
||||
|
||||
@ -1179,6 +1191,14 @@ bool TCPHandler::isQueryCancelled()
|
||||
/// During request execution the only packet that can come from the client is stopping the query.
|
||||
if (static_cast<ReadBufferFromPocoSocket &>(*in).poll(0))
|
||||
{
|
||||
if (in->eof())
|
||||
{
|
||||
LOG_INFO(log, "Client has dropped the connection, cancel the query.");
|
||||
state.is_cancelled = true;
|
||||
state.is_connection_closed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
UInt64 packet_type = 0;
|
||||
readVarUInt(packet_type, *in);
|
||||
|
||||
|
@ -57,6 +57,7 @@ struct QueryState
|
||||
|
||||
/// Is request cancelled
|
||||
bool is_cancelled = false;
|
||||
bool is_connection_closed = false;
|
||||
/// empty or not
|
||||
bool is_empty = true;
|
||||
/// Data was sent.
|
||||
|
Loading…
Reference in New Issue
Block a user