Skip to content

Commit 490693b

Browse files
authored
Merge pull request #328 from dwnusbaum/release-connections
Always call Connector.release after Connector.connect
2 parents dea7f91 + 75219bb commit 490693b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ public FormValidation doTestConnection(
291291

292292
try {
293293
GitHub connect = Connector.connect(apiUri, gitHubAppCredential);
294-
return FormValidation.ok("Success, Remaining rate limit: " + connect.getRateLimit().getRemaining());
294+
try {
295+
return FormValidation.ok("Success, Remaining rate limit: " + connect.getRateLimit().getRemaining());
296+
} finally {
297+
Connector.release(connect);
298+
}
295299
} catch (Exception e) {
296300
return FormValidation.error(e, String.format(ERROR_AUTHENTICATING_GITHUB_APP, appID));
297301
}

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,15 +2025,19 @@ public FormValidation doValidateRepositoryUrlAndCredentials(@CheckForNull @Ances
20252025
StringBuilder sb = new StringBuilder();
20262026
try {
20272027
GitHub github = Connector.connect(info.getApiUri(), credentials);
2028-
if (github.isCredentialValid()){
2029-
sb.append("Credentials ok.");
2030-
}
2028+
try {
2029+
if (github.isCredentialValid()){
2030+
sb.append("Credentials ok.");
2031+
}
20312032

2032-
GHRepository repo = github.getRepository(info.getRepoOwner() + "/" + info.getRepository());
2033-
if (repo != null) {
2034-
sb.append(" Connected to ");
2035-
sb.append(repo.getHtmlUrl());
2036-
sb.append(".");
2033+
GHRepository repo = github.getRepository(info.getRepoOwner() + "/" + info.getRepository());
2034+
if (repo != null) {
2035+
sb.append(" Connected to ");
2036+
sb.append(repo.getHtmlUrl());
2037+
sb.append(".");
2038+
}
2039+
} finally {
2040+
Connector.release(github);
20372041
}
20382042
} catch (IOException e) {
20392043
return FormValidation.error(e, "Error validating repository information. " + sb.toString());
@@ -2133,12 +2137,16 @@ public ListBoxModel doFillOrganizationItems(@CheckForNull @AncestorInPath Item c
21332137
try {
21342138
StandardCredentials credentials = Connector.lookupScanCredentials(context, apiUri, credentialsId);
21352139
GitHub github = Connector.connect(apiUri, credentials);
2136-
if (!github.isAnonymous()) {
2137-
ListBoxModel model = new ListBoxModel();
2138-
for (Map.Entry<String,GHOrganization> entry : github.getMyOrganizations().entrySet()) {
2139-
model.add(entry.getKey(), entry.getValue().getAvatarUrl());
2140+
try {
2141+
if (!github.isAnonymous()) {
2142+
ListBoxModel model = new ListBoxModel();
2143+
for (Map.Entry<String,GHOrganization> entry : github.getMyOrganizations().entrySet()) {
2144+
model.add(entry.getKey(), entry.getValue().getAvatarUrl());
2145+
}
2146+
return model;
21402147
}
2141-
return model;
2148+
} finally {
2149+
Connector.release(github);
21422150
}
21432151
}
21442152
catch (FillErrorResponse e) {

0 commit comments

Comments
 (0)