eclipse-ee4j / eclipse-ee4j/jersey

RequestScope is not released if Exception occurs while writing response

Open
#3,471 8 comments 0 reactions 0 assignees View on GitHub
Component: core Priority: Major Type: Bug
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.