eclipse-ee4j / eclipse-ee4j/jersey
RequestScope is not released if Exception occurs while writing response
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
The RequestScope is not released if an exception occurs while writing the response.
What happens is that in the catch block of ContainerResponse.writerResponse() the method processingContext.asyncContext() is called, which results in calling AsyncResponderHolder.get().
The actual bug seems to be in AsyncResponderHolder.get(), which is, in fact, a setter:
```
public AsyncContext get() {
final AsyncResponder ar = new AsyncResponder(responder, scopeInstance, externalScope, externalContext);
asyncResponder = ar;
return ar;
}
```
This prevents the scopeInstance to be released:
```
private static class AsyncResponderHolder implements Value {
...
public void release() {
if (asyncResponder == null) {
scopeInstance.release();
}
}
}
```
#### Environment
Tested on Linux, but source code analysis reveals that this issue is os-unrelated.
#### Affected Versions
[2.24.1]
Contributor guide
Research direction
Start in ContainerResponse.writerResponse() and trace processingContext.asyncContext() into AsyncResponderHolder.get() and release(). Verify the exception path and the conditions under which scopeInstance.release() is skipped. Done means the RequestScope is released when response writing raises an exception, with regression coverage in the relevant Jersey tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100