Github user TomasHofman commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2287#discussion_r231878791
  
    --- Diff: 
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileLockNodeManager.java
 ---
    @@ -299,44 +303,52 @@ protected FileLock tryLock(final long lockPos) throws 
IOException {
     
        protected FileLock lock(final long lockPosition) throws Exception {
           long start = System.currentTimeMillis();
    +      boolean isRecurringFailure = false;
     
           while (!interrupted) {
    -         FileLock lock = tryLock(lockPosition);
    -
    -         if (lock == null) {
    -            try {
    -               Thread.sleep(500);
    -            } catch (InterruptedException e) {
    -               return null;
    +         try {
    +            FileLock lock = tryLock(lockPosition);
    +            isRecurringFailure = false;
    +
    +            if (lock == null) {
    +               try {
    +                  Thread.sleep(500);
    +               } catch (InterruptedException e) {
    +                  return null;
    +               }
    +
    +               if (lockAcquisitionTimeout != -1 && 
(System.currentTimeMillis() - start) > lockAcquisitionTimeout) {
    +                  throw new Exception("timed out waiting for lock");
    +               }
    +            } else {
    +               return lock;
                 }
    -
    -            if (lockAcquisitionTimeout != -1 && 
(System.currentTimeMillis() - start) > lockAcquisitionTimeout) {
    -               throw new Exception("timed out waiting for lock");
    +         } catch (IOException e) {
    +            // IOException during trylock() may be a temporary issue, e.g. 
NFS volume not being accessible
    +
    +            logger.log(isRecurringFailure ? Logger.Level.DEBUG : 
Logger.Level.WARN,
    +                    "Failure when accessing a lock file", e);
    +            isRecurringFailure = true;
    +
    +            long waitTime = LOCK_ACCESS_FAILURE_WAIT_TIME;
    +            if (lockAcquisitionTimeout != -1) {
    +               final long remainingTime = lockAcquisitionTimeout - 
(System.currentTimeMillis() - start);
    +               if (remainingTime <= 0) {
    +                  throw new Exception("timed out waiting for lock");
    +               }
    +               waitTime = Collections.min(Arrays.asList(waitTime, 
remainingTime));
    --- End diff --
    
    Good point, updated.


---

Reply via email to