Siyao Meng created RATIS-2734:
---------------------------------

             Summary: AsyncApi.send(message, replication) fails with 
NullPointerException in RaftServerImpl.watchAsync
                 Key: RATIS-2734
                 URL: https://issues.apache.org/jira/browse/RATIS-2734
             Project: Ratis
          Issue Type: Bug
          Components: server
    Affects Versions: 3.3.1, 3.3.0
            Reporter: Siyao Meng


A write sent with a replication level other than MAJORITY, for example 
{{client.async().send(message, ReplicationLevel.ALL_COMMITTED)}}, never 
succeeds. The leader applies the write and then throws a NullPointerException 
while waiting for the replication level. The client receives 
{{java.io.IOException: java.lang.NullPointerException}} and retries until its 
retry policy gives up.

{code}
Caused by: java.lang.NullPointerException
        at 
org.apache.ratis.server.impl.RaftServerImpl.watchAsync(RaftServerImpl.java:1099)
        at 
org.apache.ratis.server.impl.RaftServerImpl.waitForReplication(RaftServerImpl.java:968)
        at 
org.apache.ratis.server.impl.RaftServerImpl.lambda$writeAsync$15(RaftServerImpl.java:1061)
{code}

h3. Cause

RATIS-2497 added a check at the top of {{RaftServerImpl.watchAsync}}:

{code:java}
if (OrderedAsync.DUMMY.getContent().equals(request.getMessage().getContent())) {
{code}

{{RaftServerImpl.waitForReplication}} (added by RATIS-1994) builds its internal 
watch request with {{RaftClientRequest.newBuilder()}} and does not set a 
message, so {{request.getMessage()}} is null.

This affects 3.3.0, 3.3.1 and master.

h3. Why the tests pass

{{RaftAsyncTests.runTestWriteAsyncCustomReplicationLevel}} does not wait for 
the futures returned by {{send}}. The client is closed at the end of the try 
block before any reply arrives, every future completes with 
{{AlreadyClosedException}}, and the callback only logs the exception. The 
server path is never exercised.

h3. How to reproduce

Change the test to wait for each reply, for example {{send(...).get(10, 
TimeUnit.SECONDS)}}, and run 
{{TestRaftAsyncWithGrpc#testWriteAsyncCustomReplicationLevel}}. The first send 
times out and the log shows the stack above.

h3. Proposed fix

Make the dummy request check in {{watchAsync}} null safe, or set an empty 
message on the request built in {{waitForReplication}}. Also fix the test so 
that it waits for the replies and fails on an exception. With the null check 
and the stricter test, the test passes with both gRPC and Netty.



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

Reply via email to