Transport client throwing NPE when closing

(Chris Gatihi) #1


I'm using ES and Transport 5.5.2 and getting an NPE thrown when closing the transport client:

// Shut down existing client if open
    if (client != null) {"Detected open Transport client - closing it");
      try {
        if (client.threadPool() != null)
      } catch (Exception e) {
        String message = "An exception was thrown when attempting to close the Transport client: ";
        logger.error(message, e);

Here's what that logger entry in the last line produces:

message: An exception was thrown when attempting to close the Transport client: stack_trace: java.lang.NullPointerException: null

Note that the client and threadpool objects themselves aren't null since I'm checking for null so it seems to be something internal to either TransportClient.close() or ThreadPool.shutdown() that's causing this.

Any ideas?

(David Pilato) #2

Why are you manually closing the Threadpool. It's already done by the close method AFAIK:

(Chris Gatihi) #3

Thanks @dadoonet. I think it was in documentation somewhere. I can remove that. Do you think that could be causing the problem? i.e. we are trying to close the thread pool after it has already been closed (and nullified?) by the call to TransportClient.close()?

(David Pilato) #4

Yeah may be.

(Chris Gatihi) #5

Thanks for the pointer @dadoonet. Removing the code that was closing the threadpools manually got rid of the NPE. But now I'm seeing an IllegalStateException when I call TransportClient.close():

java.lang.IllegalStateException: thread was not started
 	at io.netty.util.concurrent.GlobalEventExecutor.awaitInactivity(
 	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.close(

Have you seen such before?

(David Pilato) #6

You should call


(Chris Gatihi) #7

Actually, that is what I'm calling. Not doing a static call to TransportClient.close(). Just wanted to be clear what class I was making that call against. I have a variable client of type TransportClient that I'm calling close on as you've suggested: client.close().

(David Pilato) #8

Any chance that 2 threads are trying to close the same client at the same time?

(Chris Gatihi) #9

Actually, that thought had crossed my mind (one tries to close it after another has already done so results in that "thread was not started" illegal state) and, now that you mention it, I'm pretty sure that's what's happening :frowning_face: