hedera-sdk-java
hedera-sdk-java copied to clipboard
Thread leak in Client
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