[ 
https://issues.apache.org/jira/browse/RATIS-1861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze resolved RATIS-1861.
-------------------------------
    Fix Version/s: 3.0.0
       Resolution: Fixed

The pull request is now merged.  Thanks, [~insere]!

> NullPointerException in readAsync when Ratis leader is changing
> ---------------------------------------------------------------
>
>                 Key: RATIS-1861
>                 URL: https://issues.apache.org/jira/browse/RATIS-1861
>             Project: Ratis
>          Issue Type: Bug
>          Components: server
>            Reporter: huxiangpeng
>            Assignee: huxiangpeng
>            Priority: Major
>             Fix For: 3.0.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Please see 
> [code|https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L596-L605].
> When a server changes to leader, it will call the function 
> [notifyLeaderChanged()|https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java#L258]
>  in becomeLeader().
> While leaderState is updated behind, so when notifyLeaderChanged() calls 
> [readAsync()|https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java#L989]
>  , it will cause the following NullPointerException.
>  
> Caused by: java.lang.NullPointerException: 0: Server 0 not found: peers=[]
>     at java.util.Objects.requireNonNull(Objects.java:290)
>     at org.apache.ratis.util.PeerProxyMap.getProxy(PeerProxyMap.java:111)
>     at 
> org.apache.ratis.grpc.server.GrpcService$AsyncService.readIndexAsync(GrpcService.java:93)
>     at 
> org.apache.ratis.server.impl.RaftServerImpl.sendReadIndexAsync(RaftServerImpl.java:939)
>     at 
> org.apache.ratis.server.impl.RaftServerImpl.readAsync(RaftServerImpl.java:960)
>     at 
> org.apache.ratis.server.impl.RaftServerImpl.submitClientRequestAsync(RaftServerImpl.java:847)
>     at 
> org.apache.ratis.server.impl.RaftServerImpl.submitClientRequest(RaftServerImpl.java:1031)
>     at 
> org.apache.ratis.server.impl.RaftServerProxy.submitClientRequest(RaftServerProxy.java:449)
>     at 
> org.apache.iotdb.consensus.ratis.RatisConsensus.doRead(RatisConsensus.java:373)
>     at 
> org.apache.iotdb.consensus.ratis.RatisConsensus.read(RatisConsensus.java:339)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to