eclipse-ee4j / eclipse-ee4j/jersey

jersey-client does not correctly decrement the RequestScope refcount on non-2XX response

Open
#3,352 3 comments 0 reactions 0 assignees View on GitHub
Client Component: core memory-leak Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When a non-2XX response is received, JerseyInvocation#translate calls new InboundJaxrsResponse, which increments the RequestScope reference count. There is no corresponding decrement, so a reference to the RequestScope is leaked, and the cleanup code in RequestScope.Instance#release() is never run.

I have written some example test code that demonstrates the issue:
[https://github.com/joedj/jersey-client-test/](https://github.com/joedj/jersey-client-test/)
[https://github.com/joedj/jersey-client-test/blob/master/src/test/java/net/joedj/test/JerseyClientTest.java](https://github.com/joedj/jersey-client-test/blob/master/src/test/java/net/joedj/test/JerseyClientTest.java)
(apologies, the test is a bit messy as it relies on the emission of a debug log statement when the scope instance is released)

The testGood and testExplicitCloseAfterException tests both release the scope correctly, but testNoExplicitCloseAfterException does not. I don't believe an explicit exception.getResponse().close() is supposed to be required here.

I'm not sure what the actual effect of leaking these references is - it could in fact be harmless, but the comments in RequestScope.java suggest it may leak memory.
#### Affected Versions
[2.21, 2.22.2]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.