From 992d450e0a9faa73adbb06bafc5871ca7d25d5e5 Mon Sep 17 00:00:00 2001 From: Boqin Qin Date: Tue, 9 Jun 2020 04:59:17 +0800 Subject: [PATCH] servers, util: fix deadlock caused by conflicting lock order (#3340) --- servers/src/mining/stratumserver.rs | 8 +++++--- util/src/logger.rs | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/servers/src/mining/stratumserver.rs b/servers/src/mining/stratumserver.rs index 84e2884aa4..881debc1b2 100644 --- a/servers/src/mining/stratumserver.rs +++ b/servers/src/mining/stratumserver.rs @@ -714,11 +714,13 @@ impl WorkersList { } pub fn remove_worker(&self, worker_id: usize) { self.update_stats(worker_id, |ws| ws.is_connected = false); - self.workers_list - .write() + let mut stratum_stats = self.stratum_stats.write(); + let mut workers_list = self.workers_list.write(); + workers_list .remove(&worker_id) .expect("Stratum: no such addr in map"); - self.stratum_stats.write().num_workers = self.workers_list.read().len(); + + stratum_stats.num_workers = workers_list.len(); } pub fn login(&self, worker_id: usize, login: String, agent: String) -> Result<(), RpcError> { diff --git a/util/src/logger.rs b/util/src/logger.rs index 0f373feb3c..f445919b82 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -150,6 +150,8 @@ pub fn init_logger(config: Option, logs_tx: Option, logs_tx: Option