From eca3d1cb9067e4a3520eeea17d8fcae1091bc06f Mon Sep 17 00:00:00 2001 From: Chiradeep Vittal Date: Thu, 18 Aug 2011 12:06:19 -0700 Subject: [PATCH] Failed waiters could wait longer than the requested timeout (upto 2x) --- utils/src/com/cloud/utils/db/GlobalLock.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/src/com/cloud/utils/db/GlobalLock.java b/utils/src/com/cloud/utils/db/GlobalLock.java index 067ad57de30..e43ce445318 100644 --- a/utils/src/com/cloud/utils/db/GlobalLock.java +++ b/utils/src/com/cloud/utils/db/GlobalLock.java @@ -132,15 +132,20 @@ public class GlobalLock { if(ownerThread != null) { profiler.start(); try { - wait(((long)timeoutSeconds)*1000L); + wait((long)remainingMilliSeconds); } catch (InterruptedException e) { interrupted = true; } profiler.stop(); - remainingMilliSeconds -= profiler.getDuration(); - if(remainingMilliSeconds < 0) - return false; + remainingMilliSeconds -= profiler.getDuration(); + //if equal to zero, then it could come back to the wait and wait + //forever since wait(0) waits till interrupted or notified. + if (remainingMilliSeconds <= 0) { + if (s_logger.isTraceEnabled()) + s_logger.trace("timed out waiting for " + name + " last wait duration=" + profiler.getDuration()); + return false; + } continue; } else {