Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8279

Attachment inputstream starts with -1 for slow connections

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: 3.2.8
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      When a file is uploaded with a slow connection (only), using my CXF REST API, I get Couldn't find MIME boundary error. So I debugged the CXF core code to find out why. Now I'm looking at this code[1].

          private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException {
      
              // work around a bug in PushBackInputStream where the buffer isn't
              // initialized
              // and available always returns 0.
              int value = pbs.read();
              pbs.unread(value);
              while (value != -1) {
                  value = pbs.read();
      

      When the client to server connection is very slow, the first read() of the input stream almost always is -1. That results Couldn't find MIME boundary error at the later on the flow.

      If I change the code (just to debug) to skip the first byte when it's -1, like below, it works smoothly. See the 3 lines shown with "<<<<<<<". That means the data I expect is available after -1.

          private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException {
      
              // work around a bug in PushBackInputStream where the buffer isn't
              // initialized
              // and available always returns 0.
              int value = pbs.read();
              if (value == -1) {                <<<<<< if the first byte is -1,
                  value = pbs.read();           <<<<<< ignore that and read the  
              }                                 <<<<<< next byte
              pbs.unread(value);
              while (value != -1) {
                  value = pbs.read();
      

      Another important thing is this happens only for non-localhost and https connections.

      Any idea what could be the reason for giving -1 for the first read always when the connection is slow?

      [1] https://github.com/apache/cxf/blob/cxf-3.2.8/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java#L264

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bhathiya Bhathiya Jayasekara
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: