You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2025/01/22 16:29:00 UTC

[Bug 69545] New: Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

            Bug ID: 69545
           Summary: Issue Posting a huge content with header
                    transfer-encoding chunked not working from 10.1.29
                    version of tomcat in spring cloud gateway application
                    using reactive webflux
           Product: Tomcat 10
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: aravindgwda@gmail.com
  Target Milestone: ------

Hi Team,
                We have an issue when huge content is posted in the request
body for an endpoint in  spring boot  application that’s using embed tomcat
version 10.1.29 and above.
We are making a HTTP post call with Jason request body has having around 700000
characters (pdf content base 64 encoded string)

This is working in 10.1.28 and below versions.

The application is a spring cloud gateway based on reactive webflux.

Looks like the below change in the 10.1.29 version might have caused the issue.
While the tomcat reading  the http posted request it’s not reading all the
chunks of the request.

Correct a regression in the fix for non-blocking reads of chunked request
bodies that caused InputStream.available() to return a non-zero value when
there was no data to read. In some circumstances this could cause a blocking
read to block waiting for more data rather than return the data it had already
received. (markt)

Kindly request to help us with this issue fix.

Thanks,
Aravinda

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #12 from Aravinda <ar...@gmail.com> ---
Thats very good news to us. Thank you very much Remy Maucherat. Sure, will wait
for your updates.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

Matafagafo <ma...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matafagafo@gmail.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #13 from Remy Maucherat <re...@apache.org> ---
The scenario I found involved not calling available() properly. In the end I
haven't found a regression or new issue.

Basically the code in the ReadListener has to be:
do {
  int n = is.read(buf);
  if (n < 0) { // == -1 is ok too
    break;
  }
  // Do stuff
} while (is.isReady());

read returning 0 is always ok, and it needs to loop while isReady (even if read
keeps returning 0 bytes).

Not error prone at all ...

Please provide a test case to verify what is actually happening.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #10 from Aravinda <ar...@gmail.com> ---
Sorry Correcting my earlier message.
Its working in the blocking mode and not working consistently in the
non-blocking mode. 

Is there a possibility it is considering only the chunk of data in the buffer
(in non blocking mode) and the available is >0 and we are getting CR or LF and
its not reading the remaining chunks. Am not able reproduce in local but this
tomcat code fails 60% of the requests when its deployed and Openshift platform. 
We reverted to use 10.1.28 version of embed tomcat instead and its work
absolutely fine.

"For the blocking mode, this is working fine. 
The issue is happening in the spring cloud gateway application(non blocking
mode) which will just delegate the request to the downstream application after
some processing like authentication. The downstream application executes in
blocking mode. If we directly call the downstream application with the same
request its working fine.


Do we have the below code in the blocking mode too? looks like its setting
available = 0 even though the all the chunks reading/entire request body is not
read.




        if (available == 1 && parseState == ParseState.CHUNK_BODY_CRLF) {
            // Either just the CR or just the LF are left in the buffer. There
is no data to read.
            available = 0;
        } else if (available == 2 && !crFound && parseState ==
ParseState.CHUNK_BODY_CRLF) {
            // Just CRLF is left in the buffer. There is no data to read.
            available = 0;
        }"

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #7 from Remy Maucherat <re...@apache.org> ---
After trying many things and tracing, I cannot find a way to trigger
available() in blocking mode when it would likely return non 0 despite having
no meaningful bytes (in particular using the
TestChunkedInputFilter.testChunkedSplitWithReader test case).
In non blocking mode, I have not ruled it out. If you can provide a test, it
would help.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #2 from Remy Maucherat <re...@apache.org> ---
I did review the supposedly offending patch and it looks like a nice trick to
me (= it should not break).

To be honest it would be better to actually read the one or two decoration
bytes in available(). Unfortunately I decided a long time ago to not have
"throws IOE" on available() and there's no way to properly report an error. I
have ideas to work around that but let's see the test case first.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #3 from Aravinda <ar...@gmail.com> ---
Created attachment 39976
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39976&action=edit
sample screenshot of the pdf content

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #6 from Remy Maucherat <re...@apache.org> ---
The patch that added additional special case handling to available() seems
fine:
https://github.com/apache/tomcat/blob/main/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java#L202

However, while it handles ParseState.CHUNK_BODY_CRLF, it does not do
CHUNK_HEADER or others, which might similarly not produce content. So I wonder
if your "regression" could simply be a bad luck due to not doing everything.
Hard to know without a test.

I am considering that available() should actually process existing data in the
buffer (and add a throws IOE) to properly determine if there is actual data.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All
             Status|NEW                         |NEEDINFO

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
Please provide a *minimal* test case that demonstrates the issue.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #11 from Remy Maucherat <re...@apache.org> ---
Ok, I think I can reproduce it with non blocking if I split the chunk header.
Then onDataAvailable never gets called again (despite the read and the call to
isReady/available).
To be verified though ...

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #8 from Aravinda <ar...@gmail.com> ---
For the non blocking mode, this is working fine. 
The issue is happening in the spring cloud gateway application(blocking mode)
which will just delegate the request to the downstream application after some
processing like authentication. The downstream application executes in
non-blocking mode. If we directly call the downstream application with the same
request its working fine.


Do we have the below code in the blocking mode too? looks like its setting
available = 0 even though the all the chunks reading/entire request body is not
read.




        if (available == 1 && parseState == ParseState.CHUNK_BODY_CRLF) {
            // Either just the CR or just the LF are left in the buffer. There
is no data to read.
            available = 0;
        } else if (available == 2 && !crFound && parseState ==
ParseState.CHUNK_BODY_CRLF) {
            // Just CRLF is left in the buffer. There is no data to read.
            available = 0;
        }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #9 from Remy Maucherat <re...@apache.org> ---
(In reply to Aravinda from comment #8)
> For the non blocking mode, this is working fine. 
> The issue is happening in the spring cloud gateway application(blocking
> mode) which will just delegate the request to the downstream application
> after some processing like authentication. The downstream application
> executes in non-blocking mode. If we directly call the downstream
> application with the same request its working fine.
> 
> 
> Do we have the below code in the blocking mode too? looks like its setting
> available = 0 even though the all the chunks reading/entire request body is
> not read.
> 
> 
> 
> 
>         if (available == 1 && parseState == ParseState.CHUNK_BODY_CRLF) {
>             // Either just the CR or just the LF are left in the buffer.
> There is no data to read.
>             available = 0;
>         } else if (available == 2 && !crFound && parseState ==
> ParseState.CHUNK_BODY_CRLF) {
>             // Just CRLF is left in the buffer. There is no data to read.
>             available = 0;
>         }

Yes, it's valid if available() returns 0 in blocking mode, it means that there
is no data available for reading without blocking until some data becomes
available. >0 means a read will not block since data is already available in
some buffer.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEEDINFO                    |RESOLVED

--- Comment #14 from Mark Thomas <ma...@apache.org> ---
Further testing did find an issue and the root cause is understood.

Rémy has applied a fix for this issue that should also address any similar
issues.

Fixed in:
- 11.0.x for 11.0.3 onwards
- 10.1.x for 10.1.35 onwards
-  9.0.x for  9.0.99 onwards

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

Aravinda <ar...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|All                         |other
           Hardware|PC                          |Other

--- Comment #5 from Aravinda <ar...@gmail.com> ---
Hi Mark Thomas , Thanks for checking this. This one am not able to reproduce on
my  local machine but consistently failing when the micro service application
is deployed to Openshift platform. So am not sure on what test case details I
can provide.

Have attached the sample content image with PDF converted to base64 encoded
string and this one contains more than 700K characters and is sent in the json
request body. And we are getting org.apache.coyote.BadRequestException.
Attaching the screenshot of the same. 
Seems like even before reading the entire json request body it is considering
the request reading is completed.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #4 from Aravinda <ar...@gmail.com> ---
Created attachment 39977
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39977&action=edit
BadRequestException

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69545] Issue Posting a huge content with header transfer-encoding chunked not working from 10.1.29 version of tomcat in spring cloud gateway application using reactive webflux

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69545

--- Comment #15 from Aravinda <ar...@gmail.com> ---
Thats great news!!! Thank you very much Mark Thomas and Remy Maucherat! 
Do you have any tentative date for the 10.1.35 release?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org