RongtongJin commented on a change in pull request #723: Concurrent risk in 
brokerLiveTable
URL: https://github.com/apache/rocketmq/pull/723#discussion_r396249459
 
 

 ##########
 File path: 
namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
 ##########
 @@ -422,9 +424,20 @@ public void scanNotActiveBroker() {
             long last = next.getValue().getLastUpdateTimestamp();
             if ((last + BROKER_CHANNEL_EXPIRED_TIME) < 
System.currentTimeMillis()) {
                 RemotingUtil.closeChannel(next.getValue().getChannel());
-                it.remove();
-                log.warn("The broker channel expired, {} {}ms", next.getKey(), 
BROKER_CHANNEL_EXPIRED_TIME);
-                this.onChannelDestroy(next.getKey(), 
next.getValue().getChannel());
+                try {
+                    try {
+                        this.lock.writeLock().lockInterruptibly();
+                        it.remove();
+                        log.warn("The broker channel expired, {} {}ms", 
next.getKey(), BROKER_CHANNEL_EXPIRED_TIME);
+                        this.onChannelDestroy(next.getKey(), 
next.getValue().getChannel());
+                    } catch (Exception e) {
+                        log.error("Delete Not Active Broker Exception", e);
+                    } finally {
+                        this.lock.writeLock().unlock();
+                    }
+                } catch (Exception e) {
+                    log.error("Delete Not Active Broker Exception", e);
+                }
 
 Review comment:
   Nesting of try-catch still exists. 
   IMO, maybe moving the writelock out of the loop is a good choice.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to