From ee3f6082045a48e4cbd6f795101a2359b6c6c62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 2 Jun 2016 13:19:44 +0200 Subject: [PATCH] Fixing wait loop in case of spurious wake-ups. --- rpc/src/v1/helpers/signing_queue.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rpc/src/v1/helpers/signing_queue.rs b/rpc/src/v1/helpers/signing_queue.rs index 4f860e438..0ded8998c 100644 --- a/rpc/src/v1/helpers/signing_queue.rs +++ b/rpc/src/v1/helpers/signing_queue.rs @@ -125,9 +125,13 @@ impl ConfirmationPromise { let deadline = Instant::now() + timeout; info!(target: "own_tx", "Signer: Awaiting transaction confirmation... ({:?}).", self.id); - while Instant::now() < deadline { - // Park thread - thread::park_timeout(timeout); + loop { + let now = Instant::now(); + if now >= deadline { + break; + } + // Park thread (may wake up spuriously) + thread::park_timeout(deadline - now); // Take confirmation result let res = self.result.lock().unwrap(); // Check the result @@ -137,7 +141,7 @@ impl ConfirmationPromise { ConfirmationResult::Waiting => continue, } } - // We reached the timeout. Just return `None` and make sure to remove waiting. + // We reached the timeout. Just return `None` trace!(target: "own_tx", "Signer: Confirmation timeout reached... ({:?}).", self.id); None }