java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: 193fa0a4-1df0-445f-8737-18b7bb464f64 thread-id: 80
When the Redission distributed lock performs the unlock operation, there is an abnormal source code as follows:
public void unlock() {
try {
this.get(this.unlockAsync(Thread.currentThread().getId()));
} catch (RedisException var2) {
if (var2.getCause() instanceof IllegalMonitorStateException) {
throw (IllegalMonitorStateException)var2.getCause();
} else {
throw var2;
}
}
}
public RFuture<Void> unlockAsync(long threadId) {
RFuture<Boolean> future = this.unlockInnerAsync(threadId);
CompletionStage<Void> f = future.handle((opStatus, e) -> {
this.cancelExpirationRenewal(threadId);
if (e != null) {
throw new CompletionException(e);
} else if (opStatus == null) {
IllegalMonitorStateException cause = new IllegalMonitorStateException("attempt to unlock lock, not locked by current thread by node id: " + this.id + " thread-id: " + threadId);
throw new CompletionException(cause);
} else {
return null;
}
});
return new CompletableFutureWrapper(f);
}
Why is this happening, because when the lock operation is performed, a time is set
1. After you complete the lock, when the execution time of the business code in it is greater than the lock time, and unlock it, the exception will be thrown
2. The problem of multi-thread competition. When the first thread completes the lock, it is not unlocked at this time. In this way, the second thread tries to acquire the lock and perform the lock operation, and this exception will be thrown.
Solution:
Before locking or unlocking, it is enough to judge the legality of the state, instead of directly performing the locking and unlocking operation.
Read More:
- The showdialog() method in thread/threading. Timer/task reported an error: “before ole can be called, the current thread must be set to single thread unit (STA) mode.”
- [Solved] Fe node hangs up and restarts with an error sleepycat.je.locktimeoutexception: (JE 7.3.7) lock expired
- [Solved] ERROR_POLICY: attempt to perform an operation not allowed by the security policy `PDF‘ @ error/const
- [Gradle is Stucked in Building Runing] log Error: Timeout waiting to lock journal cache
- failed to obtain in-memory shard lock [How to Solve]
- [Solved] RuntimeError: An attempt has been made to start a new process before the current process…
- Solution of socket write error caused by pressing F5 to refresh page by ehcache user
- [Solved] k8s error retrieving resource lock default/fuseim.pri-ifs: Unauthorized
- [Solved] Clickhouse Error: DB::Exception: Cannot lock file /var/lib/clickhouse/status
- Android: Can’t create handler inside thread that has not called Looper.prepare() [Solved]
- laravel Error mews/captcha is locked to version 3.2.4 and an update of this package was not requested.
- [Solved] Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
- [Solved] hive Caused by: MetaException(message:Version information not found in metastore. )
- error: rpmdb: BDB0113 Thread/process 14536/140712790841152 failed: BDB1507 Thread died in Berkeley DB library
- [Solved] Initialization error encountered by JUnit unit test: Method initialization error not found
- [Solved] Android Networking error: CLEARTEXT communication to www.xxxxx.xyz not permitted by network security policy
- [GO]Solve request origin not allowed by Upgrader.CheckOrigin websocket cross-domain
- The execution of ExecuteNonQuery by oraclecommand is suspended
- [Solved] kubectl error: sou-bash: _get_comp_words_by_ref: command not found
- Node Kubelet Error: node “xxxxx“ not found [How to Solve]