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

DynamicGraphQLClient never gets closed #372

Open
yrodiere opened this issue Sep 15, 2022 · 0 comments
Open

DynamicGraphQLClient never gets closed #372

yrodiere opened this issue Sep 15, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@yrodiere
Copy link
Collaborator

yrodiere commented Sep 15, 2022

This code creates a client:

ResultHandle gitHubGraphQLClientRh = tryBlock.loadNull();
if (dispatchingConfiguration.requiresGraphQLClient()) {
gitHubGraphQLClientRh = tryBlock.invokeVirtualMethod(
MethodDescriptor.ofMethod(GitHubService.class, "getInstallationGraphQLClient", DynamicGraphQLClient.class,
long.class),
tryBlock.readInstanceField(
FieldDescriptor.of(dispatcherClassCreator.getClassName(), GITHUB_SERVICE_FIELD,
GitHubService.class),
tryBlock.getThis()),
installationIdRh);
}

By calling this:

@Override
public DynamicGraphQLClient getInstallationGraphQLClient(long installationId) {
try {
return createInstallationGraphQLClient(installationId);
} catch (IOException | ExecutionException | InterruptedException e1) {
synchronized (this) {
try {
// retry in a synchronized in case the token is invalidated in another thread
return createInstallationGraphQLClient(installationId);
} catch (IOException | ExecutionException | InterruptedException e2) {
try {
// this time we invalidate the token entirely and go for a new token
installationTokenCache.invalidate(installationId);
return createInstallationGraphQLClient(installationId);
} catch (IOException | ExecutionException | InterruptedException e3) {
throw new IllegalStateException(
"Unable to create a GitHub GraphQL client for the installation " + installationId, e3);
}
}
}
}
}

private DynamicGraphQLClient createInstallationGraphQLClient(long installationId)
throws IOException, ExecutionException, InterruptedException {
CachedInstallationToken installationToken = installationTokenCache.get(installationId);
DynamicGraphQLClient graphQLClient = DynamicGraphQLClientBuilder.newBuilder()
.url(gitHubAppRuntimeConfig.instanceEndpoint + "/graphql")
.header(AUTHORIZATION_HEADER, String.format(AUTHORIZATION_HEADER_BEARER, installationToken.getToken()))
.build();
// this call is probably - it's not documented - not counted in the rate limit
graphQLClient.executeSync("query {\n" +
"rateLimit {\n" +
" limit\n" +
" cost\n" +
" remaining\n" +
" resetAt\n" +
" }\n" +
"}");
return graphQLClient;
}

But as far as I can tell, there is absolutely no code to call the close() method on the created client.

Maybe we should just close it after all events have been processed? (careful though, it's reactive code so it's non-trivial to say when processing ends exactly...)

Maybe it should be cached like the non-graphQL client, and renewed every 10 minutes, and closed after 20 minutes?

@yrodiere yrodiere added the bug Something isn't working label Sep 15, 2022
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

No branches or pull requests

1 participant