Differences in calling WriteListener.onError
- Dominant language
- Java
- Stars
- 325
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
If an async servlet is in a loop like:
```java
ServletOutputStream out = response.getOutputStream();
out.setWriteListener(new WriteListener()
{
public void onWritePossible()
{
try
{
while (out.isReady())
out.write(someBuffer);
}
catch(Throwable t)
{
t.printStackTrace();
}
}
public void onError(Throwable t)
{
t.printStackTrace();
}
});
```
and the client receiving the response closes the connection at some point, then we see different behaviors from Jetty, Tomcat and Undertow:
- Jetty throws from write and calls onError with a different exception. If `isReady()` is called it returns true.
- Tomcat throws from write and calls onError with the cause of the original exception. If `isReady()` is called it returns false.
- Undertow throws from the write, but never calls onError. If `isReady()` is called it return false, but then `onError` is still not called.
I'm not sure any of these behaviors is strictly correct:
+ should onError be called for an exception that has already been thrown to the application?
+ should onError every be called if `isReady()` has not been called and has not returned false?
+ should the write every actually throw? instead should `isReady()` return false and then `onError` is called with the problem?
+ if the write has thrown, what should `isReady()` return?
Contributor guide
Research direction
Start by comparing the reported WriteListener behavior across onWritePossible, onError, isReady, and write when the client disconnects. Done means resolving the competing behaviors into a clear, consistent API contract and documenting which callback, return value, and exception behavior is expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100