Better diagnostics when client has dropped connection

This commit is contained in:
Alexey Milovidov 2020-10-24 06:41:47 +03:00
parent 13b8dce792
commit 74558a4e27
2 changed files with 24 additions and 3 deletions

View File

@ -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);

View File

@ -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.