amaliujia commented on code in PR #1621:
URL: https://github.com/apache/ratis/pull/1621#discussion_r4214063735


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java:
##########
@@ -687,7 +691,11 @@ private Collection<LogAppender> 
addSenders(Collection<RaftPeer> newPeers, long n
     final List<LogAppender> newAppenders = newPeers.stream().map(peer -> {
       final FollowerInfo f = new FollowerInfoImpl(server.getMemberId(), peer, 
this::getPeer, t, nextIndex, caughtUp);
       followerInfoMap.put(peer.getId(), f);
-      raftServerMetrics.addFollower(peer.getId());
+      synchronized (followerMetricsLock) {
+        if (!isStopped.get()) {

Review Comment:
   Can we move the synchronization down and put it after the stop check? 
   
   I think this can minimize the critical section. The race only happens here 
if the `isStopped` is false, and right after that moment, this thread 
interrupts, then another thread calls `stop()`.
   
   If `isStopped` already is true, we can skip the attempt to acquire the lock 
at all.



-- 
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]

Reply via email to