My app is opening thousands of new pools and threads of ForkJoinPool, without them ever closing but instead stays in WAIT
status, until the program eventually throws OOM error (but still does not crash):
jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
// ...stacktrace
[95433.690s][warning][os,thread] Failed to start thread "Unknown thread" - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
[95433.691s][warning][os,thread] Failed to start the native thread for java.lang.Thread "pool-1917-thread-1"
Caused by: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
The only part that uses ForkJoinPool in my program is from the openfga library, for example:
// my code that calls the library
var response = fgaClient.listRelations(body, options).get();
// listRelations() in the library
public CompletableFuture<ClientListRelationsResponse> listRelations(ClientListRelationsRequest request, ClientListRelationsOptions listRelationsOptions) throws FgaInvalidParameterException {
// implementation...
return this.batchCheck(batchCheckRequests, options.asClientBatchCheckOptions())
.thenCompose(responses -> call(() -> ClientListRelationsResponse.fromBatchCheckResponses(responses)));
}
Can someone give me an idea of what's going on? How do I fix this?
Edit: this is a library bug and was fixed in version 0.7.2
Thanks for raising this. In this case, it's a bug in the underlying OpenFGA SDK.
In the OpenFGA Java SDK, a new executor is created on every call to BatchCheck, but never shut down.
The OpenFGA team is tracking it here, and have a PR with a fix for it that should be merged soon.
As this is a bug in the library, I would suggest closing the question here and following the linked issue for updates.