Release pooled connection after DELETE to prevent pool exhaustion#1327
Open
buehlmann wants to merge 1 commit into
Open
Release pooled connection after DELETE to prevent pool exhaustion#1327buehlmann wants to merge 1 commit into
buehlmann wants to merge 1 commit into
Conversation
AbstractApi.delete(...) returned the JAX-RS Response without reading its entity or closing it. Most delete callers are void (e.g. GroupApi.deleteGroup, ProjectApi.deleteProject) and discard the returned Response, so with a pooling/Apache connector (used for proxied clients) the underlying connection is never returned to the pool. GitLabs delete endpoints answer 200/202 with a body, so each such delete leaks one pooled connection; with the default of 2 connections per route the pool is quickly exhausted and subsequent requests block indefinitely in AbstractConnPool.getPoolEntryBlocking. This issue was not visible before gitlab4j#1312: setting client properties per request kept the ClientConfig RequestScoped, so the connector (and its pool) was rebuilt per request and any leaked connection was discarded with it. Since gitlab4j#1312 the ClientConfig is a singleton and the pool is shared, so the leak now accumulates and exhausts the pool. Buffer the delete body via Response.bufferEntity() in the delete() helpers. This releases the connection immediately while keeping the Response readable for the few callers that consume it (LicenseApi.deleteLicense, IssuesApi.deleteIssueLink, EpicsApi.removeIssue). get/post/put are unaffected since those callers already release the connection via readEntity().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AbstractApi.delete(...) returned the JAX-RS Response without reading its entity or closing it. Most delete callers are void (e.g. GroupApi.deleteGroup, ProjectApi.deleteProject) and discard the returned Response, so with a pooling/Apache connector (used for proxied clients) the underlying connection is never returned to the pool. GitLabs delete endpoints answer 200/202 with a body, so each such delete leaks one pooled connection; with the default of 2 connections per route the pool is quickly exhausted and subsequent requests block indefinitely in AbstractConnPool.getPoolEntryBlocking.
This issue was not visible before #1312: setting client properties per request kept the ClientConfig RequestScoped, so the connector (and its pool) was rebuilt per request and any leaked connection was discarded with it. Since #1312 the ClientConfig is a singleton and the pool is shared, so the leak now accumulates and exhausts the pool.
Buffer the delete body via Response.bufferEntity() in the delete() helpers. This releases the connection immediately while keeping the Response readable for the few callers that consume it (LicenseApi.deleteLicense, IssuesApi.deleteIssueLink, EpicsApi.removeIssue). get/post/put are unaffected since those callers already release the connection via readEntity().
This fix was tested against a self-hosted GitLab instance, both with and without a proxy. In both cases, all groups were deleted successfully, and no connection leaks were observed.
This PR fixes #1328