Arnaud Nauwynck edited a comment on Bug JENKINS-13828

Hi,

I also encountered this bug ... and I have implemented a workaround, that avoid restarting my jenkins master.
The workaround is a groovy script to execute as admin in the web page "https://<<jenkins>>/script"

ForceUnlockLatch.groovy
import hudson.plugins.locksandlatches.LockWrapper;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.AbstractOwnableSynchronizer;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

String lockName = "xxx-lock-name";

String text = "";
LockWrapper.DescriptorImpl descr = LockWrapper.DESCRIPTOR;
// invoke field "backupLocks"
Field backupLocksField = LockWrapper.DescriptorImpl.class.getDeclaredField("backupLocks");
backupLocksField.setAccessible(true);
Map<String,Object> backupLocks = (Map<String,Object>) backupLocksField.get(descr);

ReentrantLock lockObj = (ReentrantLock) backupLocks.get(lockName);

if (lockObj == null) {
  text += "NULL : lock not found";
} else if (lockObj.isLocked()) {
  text += "*** before Unlock: " + lockObj;

  if (! lockObj.isHeldByCurrentThread()) {
   // can not release from another thread... => java.lang.IllegalMonitorStateException
    // invoke "lockObj.sync.setExclusiveOwnerThread(currentThread)";
    Field syncField = lockObj.getClass().getDeclaredField("sync");
    syncField.setAccessible(true);
    AbstractOwnableSynchronizer lockSync = syncField.get(lockObj);
  
    Thread currentThread = Thread.currentThread();
    Method setExclusiveOwnerThreadMethod = AbstractOwnableSynchronizer.class.getDeclaredMethod("setExclusiveOwnerThread", Thread.class);
    setExclusiveOwnerThreadMethod.setAccessible(true);
    setExclusiveOwnerThreadMethod.invoke(lockSync, currentThread);
  }

  // *** do unlock ***
  lockObj.unlock();

  text += "\n *** after unlock:" + lockObj;
} else {
  text += "NOT locked : " + lockObj;
}

text;
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to