Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-4561

Servlet Nonblocking I/O Suppressed InputStream Closed Error

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Won't Do
    • Major
    • None
    • 8.2.0.Final
    • Web (Undertow)
    • None

    Description

      Created a Nonblocking I/O Servlet by following JEE Tutorial example here:

      https://docs.oracle.com/javaee/7/tutorial/servlets013.htm

      Due to my Eclipse Development Environment giving me the warning "Potential resource leak: 'input' may not be closed", I made a mistake by wrapping the following line with a try-with-resources statement.

      final ServletInputStream input = request.getInputStream();
      

      Unfortunately, no exception was thrown to indicate that the connection was already closed before processing was attempted, where I believe there should have been.

      I have added the relevant source code to reproduce my situation. Please see attached code.

      In the attached source, I added an AsyncListener to monitor the life cycle.

      Case 1

      Client Request:

      curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data '{"records":[{"key":"key1","value":"SGVsbG8gV29ybGQ="}]}' "http://localhost:8080/webapp/test/test"; echo
      

      The handleRequestAsPerJeeTutorialWithInputStreamIssue method will give the following output:

      2015-04-27 10:57:20,337 (INFO ) [] AsyncIOServletTest(37): doPost(..)
      2015-04-27 10:57:50,345 (INFO ) [] AsyncIOServletTest$1(55): onTimeout called: javax.servlet.AsyncEvent@24865a17
      2015-04-27 10:57:50,359 (INFO ) [] AsyncIOServletTest$1(48): onComplete called: javax.servlet.AsyncEvent@54ff11f3
      

      Client Response:

      <html><head><title>Error</title></head><body>Internal Server Error</body></html>
      

      Case 2

      Client Request:

      curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data '{"records":[{"key":"key1","value":"SGVsbG8gV29ybGQ="}]}' "http://localhost:8080/webapp/test/test"; echo
      

      The handleRequestAsPerJeeTutorial method will give the following output:

      2015-04-27 10:56:32,111 (INFO ) [] AsyncIOServletTest(37): doPost(..)
      2015-04-27 10:56:32,114 (INFO ) [] AsyncIOServletTest(84): handleRequestAsPerJeeTutorial(..)
      2015-04-27 10:56:32,121 (INFO ) [] AsyncIOServletTest$2(97): onDataAvailable()
      2015-04-27 10:56:32,121 (INFO ) [] AsyncIOServletTest$2(115): onAllDataRead()
      2015-04-27 10:56:32,125 (INFO ) [] AsyncIOServletTest$1(48): onComplete called: javax.servlet.AsyncEvent@3746c9ed
      

      Client Response:

      ...the response...
      

      It is my opinion that a closed InputStream should cause an exception of some sort. And in this case at minimum, I think that the AsyncListener's onError should be called.

      Attachments

        Activity

          People

            sdouglas1@redhat.com Stuart Douglas
            marks1900 Mark N/A (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: