Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new thread is being created for every OpenFgaClient call #46

Closed
Jacksongoulart opened this issue Jan 23, 2024 · 3 comments · Fixed by #52
Closed

A new thread is being created for every OpenFgaClient call #46

Jacksongoulart opened this issue Jan 23, 2024 · 3 comments · Fixed by #52
Labels
bug Something isn't working

Comments

@Jacksongoulart
Copy link

Description

A new HttpClient is being created for each request, leading to an increasing number of threads. Specifying a thread pool alleviates the problem, but not completely. The issue happens because here a new HttpClient is built everytime.

Version of SDK

v0.3.1

Reproduction

Below is an example of how to reproduce the issue.

  1. Initialize OpenFgaClient with any set of configs;
  2. Invoke method OpenFgaClient#write(ClientWriteRequest request) multiple times;
  3. Notice that for every write call, a new thread is created. If you have 300k write calls, 300k threads are created, eventually running out of memory.

Expected behavior

It should not create a new thread for every request.

@Jacksongoulart Jacksongoulart added the bug Something isn't working label Jan 23, 2024
@paulosuzart
Copy link
Contributor

Just to add: In the meantime, a workaround was:

        var apiClient = new ApiClient()
                .setHttpClientBuilder(HttpClient.newBuilder()
                        .executor(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())));
        return new OpenFgaClient(config, apiClient);

This way, we control the pool to be used by the N HttpClients.

@jimmyjames
Copy link
Contributor

Thanks for reporting, you are correct; we should not create a new http client for each request.

@rhamzeh
Copy link
Member

rhamzeh commented Jan 26, 2024

Thanks for the keen eye @Jacksongoulart 🕵🏽

The fix is now out in v0.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants