Felipe Issa
Felipe Issa

Reputation: 558

NullPointerException on cassandra ThriftServer stop

I'm using cassandra to store data on my application. Everything goes fine until I try to stop it. When stopping, sometimes I reveice a NullPointerException as follows:

15:58:56.869 ERROR [Thread-2] [CassandraDaemon.java:185] Exception in thread Thread[Thread-2,5,main]
java.lang.NullPointerException: null
at org.apache.cassandra.thrift.ThriftServer.stop(ThriftServer.java:70) [cassandra-all-2.2.6-E001.jar:2.2.6-E001]
at org.apache.cassandra.service.CassandraDaemon.stop(CassandraDaemon.java:452) [cassandra-all-2.2.6-E001.jar:2.2.6-E001]
at org.apache.cassandra.service.CassandraDaemon.deactivate(CassandraDaemon.java:564) [cassandra-all-2.2.6-E001.jar:2.2.6-E001]
at mypackage.CassandraDaemonForTest$1.run(CassandraDaemonForTest.java:96) [testutils-6.3.0.jar:na]

According to the class source, this is the point where the problem happens:

public void stop()
{
    if (server != null)
    {
        server.stopServer();
        try
        {
            server.join();
        }
        catch (InterruptedException e)
        {
            logger.error("Interrupted while waiting thrift server to stop", e);
        }
        server = null;
    }
}

Apparrently, there are several instances of the same ThriftServer running, and when I try to deactivate, some pass the null check and causes the problem when calling the next method on the instance. My debugger show at least three calls to this method on the same instance:

method callstack

Any suggest of how to fix this?

Upvotes: 1

Views: 110

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

This was reported and fixed in CASSANDRA-12105, for versions 2.2.8, 3.0.9, 3.8, and above. If multiple threads called stop at the same time, then one could set server to null after the other thread has checked for

server != null

and then throw a NullPointerException on the following invocations

server.stopServer(); 
// or
server.join();

The method was made synchronized for an isolated check and invocation.

Consider upgrading.

Upvotes: 2

Related Questions