You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bhavesh Mistry <mi...@gmail.com> on 2020/02/27 00:34:42 UTC

Tomcat 9.31 PUT/POST Request receiving Partial Data

Hi Tomcat Team,

I have servlet filter for all requests to cache the entire PUT/POST
Payload.   When content is large 4KB or more, I am getting partial content
when I read from HttpServletRequest.getInputStream().  But I but 10 seconds
wait before consuming the input stream, I am getting entire content.  Can
you please let me know what is the correct way to wait for the entire
content is ready to consume from the tomcat servlet request input stream?


Filter Code:
If I put Thread.sleep(100000) at begin of filter, I am getting full
content.

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, FilterChain filterChain)
throws ServletException, IOException {
    CachedBodyHttpServletRequest cachedBodyHttpServletRequest = new
CachedBodyHttpServletRequest(httpServletRequest);
    filterChain.doFilter(cachedBodyHttpServletRequest, httpServletResponse);
}

// Wrapper to cache content.

public CachedBodyHttpServletRequest(HttpServletRequest request) throws
IOException {
    super(request);
    ServletInputStream inputStream = request.getInputStream();
    final int len = request.getContentLength();
    if (len >= 0) {
        cachedBody = new byte[len];
        ByteStreams.readFully(inputStream, cachedBody);
    } else {
        cachedBody = ByteStreams.toByteArray(inputStream);
    }
}


Thanks,

Bhavesh

Re: Tomcat 9.31 PUT/POST Request receiving Partial Data

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Tue, Mar 31, 2020 at 8:17 PM <jo...@wellsfargo.com.invalid>
wrote:

> -----Original Message-----
> > From: Bhavesh Mistry <mi...@gmail.com>
> > Sent: Wednesday, February 26, 2020 7:51 PM
> > To: Tomcat Users List <us...@tomcat.apache.org>
> > Subject: Re: Tomcat 9.31 PUT/POST Request receiving Partial Data
>
> > The response get truncated after 16321 bytes.  Please let me know what
> is best way to wait and in > order to consume entire request payload.
>
> > Thanks,
> > Bhavesh
>
> > On Wed, Feb 26, 2020 at 4:34 PM Bhavesh Mistry <
> mistry.p.bhavesh@gmail.com>
> > wrote:
>
> > Hi Tomcat Team,
> >
> > I have servlet filter for all requests to cache the entire PUT/POST
> > Payload.   When content is large 4KB or more, I am getting partial
> content
> > when I read from HttpServletRequest.getInputStream().  But I but 10
> > seconds wait before consuming the input stream, I am getting entire
> > content.  Can you please let me know what is the correct way to wait
> > for the entire content is ready to consume from the tomcat servlet
> request input stream?
> >
> >
> > Filter Code:
> > If I put Thread.sleep(100000) at begin of filter, I am getting full
> > content.
> >
> > @Override
> > protected void doFilterInternal(HttpServletRequest httpServletRequest,
> HttpServletResponse httpServletResponse, FilterChain filterChain) throws
> ServletException, IOException {
> >     CachedBodyHttpServletRequest cachedBodyHttpServletRequest = new
> CachedBodyHttpServletRequest(httpServletRequest);
> >     filterChain.doFilter(cachedBodyHttpServletRequest,
> > httpServletResponse); }
> >
> > // Wrapper to cache content.
> >
> > public CachedBodyHttpServletRequest(HttpServletRequest request) throws
> IOException {
> >     super(request);
> >     ServletInputStream inputStream = request.getInputStream();
> >     final int len = request.getContentLength();
> >     if (len >= 0) {
> >         cachedBody = new byte[len];
> >         ByteStreams.readFully(inputStream, cachedBody);
> >     } else {
> >         cachedBody = ByteStreams.toByteArray(inputStream);
> >     }
> > }
> >
> >
> > Thanks,
> >
> > Bhavesh
> >
>
> I have a team reporting the same issue with 9.0.31. Reverting to 9.0.30
> resolves their issue. Here are some details:
>
> STEPS done to identify cause :-
> 1.      We have tried to increase maxSwallowSize , connectionTimeout ,
> socket.appWriteBufSize="24576" on tomcat 9.0.31 but issue still persisted
> 2.      We tried to roll back java upgrade from 1.8.0.242 to 1.8.0.231 but
> issue still persisted
> 3.      Enabled SSL debug log to verify if request gets dropped at but it
> was not very helpful .
> 4.      FINALLY when we rolledback tomcat upgrade to 9.0.30 , same request
> worked fine .
>
> We were basically getting 400 error for few requests while smaller request
> always succeeds while larger request (100kb-180kb) frequently gets dropped
> or partially processed.
> Now we are using the 9.0.30 version until its resolved from tomcat side .
>

Have you tried 9.0.33 ?
I believe this is fixed in .33.

Martin

RE: Tomcat 9.31 PUT/POST Request receiving Partial Data

Posted by jo...@wellsfargo.com.INVALID.
-----Original Message-----
> From: Bhavesh Mistry <mi...@gmail.com> 
> Sent: Wednesday, February 26, 2020 7:51 PM
> To: Tomcat Users List <us...@tomcat.apache.org>
> Subject: Re: Tomcat 9.31 PUT/POST Request receiving Partial Data

> The response get truncated after 16321 bytes.  Please let me know what is best way to wait and in > order to consume entire request payload.

> Thanks,
> Bhavesh

> On Wed, Feb 26, 2020 at 4:34 PM Bhavesh Mistry <mi...@gmail.com>
> wrote:

> Hi Tomcat Team,
>
> I have servlet filter for all requests to cache the entire PUT/POST
> Payload.   When content is large 4KB or more, I am getting partial content
> when I read from HttpServletRequest.getInputStream().  But I but 10 
> seconds wait before consuming the input stream, I am getting entire 
> content.  Can you please let me know what is the correct way to wait 
> for the entire content is ready to consume from the tomcat servlet request input stream?
>
>
> Filter Code:
> If I put Thread.sleep(100000) at begin of filter, I am getting full 
> content.
>
> @Override
> protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
>     CachedBodyHttpServletRequest cachedBodyHttpServletRequest = new CachedBodyHttpServletRequest(httpServletRequest);
>     filterChain.doFilter(cachedBodyHttpServletRequest, 
> httpServletResponse); }
>
> // Wrapper to cache content.
>
> public CachedBodyHttpServletRequest(HttpServletRequest request) throws IOException {
>     super(request);
>     ServletInputStream inputStream = request.getInputStream();
>     final int len = request.getContentLength();
>     if (len >= 0) {
>         cachedBody = new byte[len];
>         ByteStreams.readFully(inputStream, cachedBody);
>     } else {
>         cachedBody = ByteStreams.toByteArray(inputStream);
>     }
> }
>
>
> Thanks,
>
> Bhavesh
>

I have a team reporting the same issue with 9.0.31. Reverting to 9.0.30 resolves their issue. Here are some details:

STEPS done to identify cause :- 
1.	We have tried to increase maxSwallowSize , connectionTimeout , socket.appWriteBufSize="24576" on tomcat 9.0.31 but issue still persisted
2.	We tried to roll back java upgrade from 1.8.0.242 to 1.8.0.231 but issue still persisted
3.	Enabled SSL debug log to verify if request gets dropped at but it was not very helpful .
4.	FINALLY when we rolledback tomcat upgrade to 9.0.30 , same request worked fine .

We were basically getting 400 error for few requests while smaller request always succeeds while larger request (100kb-180kb) frequently gets dropped or partially processed.
Now we are using the 9.0.30 version until its resolved from tomcat side .

Re: Tomcat 9.31 PUT/POST Request receiving Partial Data

Posted by Bhavesh Mistry <mi...@gmail.com>.
The response get truncated after 16321 bytes.  Please let me know what is
best way to wait and in order to consume entire request payload.

Thanks,
Bhavesh

On Wed, Feb 26, 2020 at 4:34 PM Bhavesh Mistry <mi...@gmail.com>
wrote:

> Hi Tomcat Team,
>
> I have servlet filter for all requests to cache the entire PUT/POST
> Payload.   When content is large 4KB or more, I am getting partial content
> when I read from HttpServletRequest.getInputStream().  But I but 10 seconds
> wait before consuming the input stream, I am getting entire content.  Can
> you please let me know what is the correct way to wait for the entire
> content is ready to consume from the tomcat servlet request input stream?
>
>
> Filter Code:
> If I put Thread.sleep(100000) at begin of filter, I am getting full
> content.
>
> @Override
> protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
>     CachedBodyHttpServletRequest cachedBodyHttpServletRequest = new CachedBodyHttpServletRequest(httpServletRequest);
>     filterChain.doFilter(cachedBodyHttpServletRequest, httpServletResponse);
> }
>
> // Wrapper to cache content.
>
> public CachedBodyHttpServletRequest(HttpServletRequest request) throws IOException {
>     super(request);
>     ServletInputStream inputStream = request.getInputStream();
>     final int len = request.getContentLength();
>     if (len >= 0) {
>         cachedBody = new byte[len];
>         ByteStreams.readFully(inputStream, cachedBody);
>     } else {
>         cachedBody = ByteStreams.toByteArray(inputStream);
>     }
> }
>
>
> Thanks,
>
> Bhavesh
>