Skip to content

Differences in calling WriteListener.onError #433

@lachlan-roberts

Description

@lachlan-roberts

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions