hedera-sdk-java icon indicating copy to clipboard operation
hedera-sdk-java copied to clipboard

Thread leak in Client

Open steven-sheehy opened this issue 2 years ago • 0 comments

Description

The Client class contains an Executor that it creates and manages but does not shutdown in its close() method. This causes a thread leak since threads grow but never decrease as clients come and go. This is more noticeable if you create a lot of temporary clients like the mirror node does to do periodic validation of consensus nodes.

Steps to reproduce

for (int i = 0; i < 10000; ++i) {
  try (Client client = Client.forMainnet()) {
    // Use it
  }
}

Additional context

Example shutdown code from the ExecutorService javadocs:

   try {
       pool.shutdown();
       if (!pool.awaitTermination(30, TimeUnit.SECONDS)) {
           pool.shutdownNow();
           if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
               log.warn("Pool did not terminate");
           }
       }
   } catch (InterruptedException ex) {
       pool.shutdownNow();
       Thread.currentThread().interrupt();
   }

Hedera network

mainnet

Version

v2.17.1

Operating system

No response

steven-sheehy avatar Aug 14 '22 19:08 steven-sheehy