Transport client throwing NPE when closing

Hi,

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) {
      logger.info("Detected open Transport client - closing it");
      try {
        client.close();
        if (client.threadPool() != null)
          client.threadPool().shutdown();
      } 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?

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

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()?

Yeah may be.

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(GlobalEventExecutor.java:197)
 	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.close(PreBuiltXPackTransportClient.java:63)

Have you seen such before?

You should call

client.close();

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().

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

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:

Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.