Attila Doroszlai created RATIS-1490:
---------------------------------------

             Summary: Follower should not change to candidate if already stopped
                 Key: RATIS-1490
                 URL: https://issues.apache.org/jira/browse/RATIS-1490
             Project: Ratis
          Issue Type: Bug
          Components: server
            Reporter: Attila Doroszlai
            Assignee: Attila Doroszlai


{{RaftServerImpl}} creates a new {{FollowerState}} for each vote request 
received.  The old {{FollowerState}} may trigger change to candidate role after 
it was shutdown by the server.  Both {{RaftServerImpl#requestVote}} and the 
change to candidate by {{FollowerState}} requires lock on {{server}} 
({{RaftServerImpl}} object).  The order of events which triggers the problem:

# {{RaftServerImpl}} executing {{requestVote}} [with lock on 
itself|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L1099]
# {{FollowerState}} [checks conditions, then waits for lock on 
{{server}}|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java#L126-L130]
# {{RaftServerImpl}} [shuts down old {{FollowerState}}, starts new 
one|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L475-L477]
# {{RaftServerImpl}} [sets last RPC time on new 
{{FollowerState}}|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L1116-L1117]
# {{RaftServerImpl}} [releases 
lock|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L1127]
# *old* {{FollowerState}} [enters block with lock on {{server}}, triggers 
change to 
candidate|https://github.com/apache/ratis/blob/b57be797fe97c00abc0e3d7353d30e1b2961714d/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java#L130-L138]



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to