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