Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1784

Exception during chunked transfer is suppressed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 4.6.0.Final
    • 3.6.2.Final
    • None
    • None

      Regression seen with resteasy 3.1.4: An exception thrown during chunked transfer is erroneously suppressed by resteasy. Thus the servlet container deems the call successful and writes a valid end-chunk, the client has no chance to see that there was an error. One common usecase would be to detect whether a large download was completed successfully.

      Reproducable by e.g.:

          @Path("ErrorAfterFlushWithoutBody")
          @GET
          @Produces(MediaType.APPLICATION_OCTET_STREAM)
          public void errorAfterFlushWithoutBody(@Context HttpServletResponse response) throws IOException {
              response.getOutputStream().flush();
              throw new IOException("a strange io error");
          }
      
          @Test
          public void testFlushWithoutBody() throws Exception {
              String data = NetworkClient.readIgnoreException("localhost", service.getPort(), "/ErrorAfterFlushWithoutBody");
      
              Assert.assertTrue(data.startsWith("HTTP/1.1 200 "));
              Assert.assertTrue(data.contains("Transfer-Encoding: chunked"));
              // there must be no end-chunk
              Assert.assertFalse(data.endsWith("0"));
          }
      
      

      It seems this problem was introduced by this change in SynchronousDispatcher:writeException during RESTEASY-1238 since 3.0.23.Final, 3.1.3.Final .

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      -      if (response.isCommitted()) throw new UnhandledException(Messages.MESSAGES.responseIsCommitted(), e);
      +      if (response.isCommitted())
      +      {
      +         LogMessages.LOGGER.debug(Messages.MESSAGES.responseIsCommitted());
      +         return;
      +      }
      

      (... Error handling during chunked transfers is a long sore point. Tomcat was broken until early tomcat8: wrote a valid end-chunk on exception although it should terminate the connection without end-chunk. Apache HttpClient until ~2 years ago was also broken, it simply ignored missing end-chunks due to some broken IIS which always omitted end-chunks. Browsers always ignore missing end-chunks because users have no good options on how to deal with it. The Problem was finally fixed in tomcat+httpclient and i am unhappy to see it resurface with resteasy)

        1. 4CFA345F-D5BE-46F0-98C6-B3054FAD0422.png
          814 kB
          Weinan Li
        2. 9C3F5FA8-42ED-4D4D-9A48-CE64E50DBD2E.png
          645 kB
          Weinan Li
        3. image-2020-01-07-13-55-01-011.png
          296 kB
          Weinan Li
        4. screenshot-1.png
          690 kB
          Weinan Li
        5. screenshot-2.png
          124 kB
          Weinan Li
        6. screenshot-3.png
          705 kB
          Weinan Li
        7. screenshot-4.png
          1.17 MB
          Weinan Li
        8. screenshot-5.png
          664 kB
          Weinan Li
        9. screenshot-6.png
          280 kB
          Weinan Li

              weli@redhat.com Weinan Li
              markuskull Markus Kull (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: