marmot-z commented on code in PR #14730:
URL: https://github.com/apache/dubbo/pull/14730#discussion_r1978706747


##########
dubbo-common/src/main/java/org/apache/dubbo/common/utils/LockUtils.java:
##########
@@ -31,18 +31,24 @@ public class LockUtils {
 
     public static void safeLock(Lock lock, int timeout, Runnable runnable) {
         try {
-            if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
-                logger.error(
-                        LoggerCodeConstants.INTERNAL_ERROR,
-                        "",
-                        "",
-                        "Try to lock failed, timeout: " + timeout,
-                        new TimeoutException());
+            boolean interrupted = false;
+            try {
+                if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
+                    logger.error(
+                            LoggerCodeConstants.INTERNAL_ERROR,
+                            "",
+                            "",
+                            "Try to lock failed, timeout: " + timeout,
+                            new TimeoutException());
+                }
+            } catch (InterruptedException e) {
+                logger.warn(LoggerCodeConstants.INTERNAL_ERROR, "", "", "Try 
to lock failed", e);
+                interrupted = true;
             }
             runnable.run();

Review Comment:
   This may seem a bit strange, because generally the tryLock method is used 
like this:
   ```java
    Lock lock = ...;
     if (lock.tryLock()) {
         try {
             // do something with lock
             runnable.run();
         } finally {
             lock.unlock();
         }
     } 
   ```
   
   Wouldn't this really lead to some race conditions?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to