Fixed error in ZK library [#CLICKHOUSE-3753]

This commit is contained in:
Alexey Milovidov 2018-05-31 22:26:21 +03:00
parent 848032ef16
commit 5dbd5b6d68
2 changed files with 10 additions and 8 deletions

View File

@ -996,13 +996,14 @@ void ZooKeeper::receiveEvent()
void ZooKeeper::finalize(bool error_send, bool error_receive)
{
std::unique_lock lock(finalize_mutex, std::defer_lock);
if (!lock.try_lock())
return;
{
/// Will wait for pushRequest method.
std::unique_lock lock(expired_mutex);
if (expired)
return;
expired = true;
if (expired)
return;
expired = true;
}
active_session_metric_increment.destroy();
@ -1020,6 +1021,7 @@ void ZooKeeper::finalize(bool error_send, bool error_receive)
/// This happens for example, when "Cannot push request to queue within operation timeout".
tryLogCurrentException(__PRETTY_FUNCTION__);
}
send_thread.join();
}
@ -1348,7 +1350,7 @@ void ZooKeeper::pushRequest(RequestInfo && info)
/// to avoid forgotten operations in the queue when session is expired.
/// Invariant: when expired, no new operations will be pushed to the queue in 'pushRequest'
/// and the queue will be drained in 'finalize'.
std::lock_guard lock(finalize_mutex);
std::lock_guard lock(expired_mutex);
if (expired)
throw Exception("Session expired", ZSESSIONEXPIRED);

View File

@ -573,7 +573,7 @@ private:
std::atomic<XID> xid {1};
std::atomic<bool> expired {false};
std::mutex finalize_mutex;
std::mutex expired_mutex;
using clock = std::chrono::steady_clock;