protect socket timeouts

This commit is contained in:
Yakov Olkhovskiy 2024-07-29 06:17:35 +00:00
parent 6e3dccf365
commit 08229390df
2 changed files with 9 additions and 1 deletions

View File

@ -366,7 +366,10 @@ void TCPHandler::runImpl()
try
{
/// If a user passed query-local timeouts, reset socket to initial state at the end of the query
SCOPE_EXIT({state.timeout_setter.reset();});
SCOPE_EXIT({
std::scoped_lock lock(in_mutex, out_mutex);
state.timeout_setter.reset();
});
/** If Query - process it. If Ping or Cancel - go back to the beginning.
* There may come settings for a separate query that modify `query_context`.
@ -779,6 +782,8 @@ void TCPHandler::extractConnectionSettingsFromContext(const ContextPtr & context
bool TCPHandler::readDataNext()
{
std::scoped_lock lock(in_mutex);
Stopwatch watch(CLOCK_MONOTONIC_COARSE);
/// Poll interval should not be greater than receive_timeout

View File

@ -229,6 +229,9 @@ private:
/// `out_mutex` protects `out` (WriteBuffer).
/// So it is used for method sendData(), sendProgress(), sendLogs(), etc.
std::mutex out_mutex;
/// `in_mutex` protects `in` (ReadBuffer)
/// Used in readDataNext() and to protect socket timeout settings
std::mutex in_mutex;
/// `task_callback_mutex` protects tasks callbacks.
/// Inside these callbacks we might also change cancellation status,
/// so it also protects cancellation status checks.