Skip to content

SelectorManager threads stay open after remote command execution and even after closing RemoteDatabase #2458

@achim-haeberle-fnt

Description

@achim-haeberle-fnt

ArcadeDB version: 25.6.1-java17

Running on Windows11 with java:
OpenJDK Runtime Environment Temurin-17.0.16+8 (build 17.0.16+8)
OpenJDK 64-Bit Server VM Temurin-17.0.16+8 (build 17.0.16+8, mixed mode, sharing)

When running a program which executes many requests with different threads (or different RemoteDatabase objects) the HttpClient-x-SelectorManager threads keep piling up until you get an out of memory error on client side. The cause for this seems to be a bug in the JDK (see https://bugs.openjdk.org/browse/JDK-8308364 and https://bugs.openjdk.org/browse/JDK-8308691). It unfortunately cannot be solved properly on client side.

See example ArcadeDBTest.java which does not lead to an out of memory as the number is not high enough, but with a profiler like visualvm you can see the 500 leftover threads.

A "dirty" workaround would be to add something like the following code to the close() mehtod of the RemoteDatabase, but I'm not convinced that this is a good solution (obviously ;)):

Field clientImplField = Class.forName("jdk.internal.net.http.HttpClientFacade").getDeclaredField("impl");
clientImplField.setAccessible(true);
Object clientImpl = clientImplField.get(httpClient);
Field selmgrField = Class.forName("jdk.internal.net.http.HttpClientImpl").getDeclaredField("selmgr");
selmgrField.setAccessible(true);
Thread selmgr = (Thread) selmgrField.get(clientImpl);
selmgr.interrupt();

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions