If an async servlet is in a loop like:
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?
If an async servlet is in a loop like:
and the client receiving the response closes the connection at some point, then we see different behaviors from Jetty, Tomcat and Undertow:
isReady()is called it returns true.isReady()is called it returns false.isReady()is called it return false, but thenonErroris still not called.I'm not sure any of these behaviors is strictly correct:
isReady()has not been called and has not returned false?isReady()return false and thenonErroris called with the problem?isReady()return?