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 2019/07/19 08:37:26 UTC
[Bug 63573] New: For some requests, ServletInputStream.read(byte[]
buffer) repeatedly returns 0 at EOF, fails to return -1
https://bz.apache.org/bugzilla/show_bug.cgi?id=63573
Bug ID: 63573
Summary: For some requests, ServletInputStream.read(byte[]
buffer) repeatedly returns 0 at EOF, fails to return
-1
Product: Tomcat 8
Version: 8.5.38
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Catalina
Assignee: dev@tomcat.apache.org
Reporter: ferhat.savci@cs.com.tr
Target Milestone: ----
This happens for 5-12 POST requests daily, on a system that gets around 50,000
POST requests a day. All POST requests are for the same servlet, an XML payload
is posted to it.
I've traced the code to InputBuffer.read(byte,offset,length) and the problem is
probably with InputBuffer.checkByteBufferEof() which seems to determine if EOF
is reached in that code.
When it happens, the simple stream copy loop below will turn into a tight, CPU
hogging endless loop with each read returning 0 bytes:
InputStream xmlis = request.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int n = 0;
byte[] buff = new byte[xmlis.available()];
do {
n = xmlis.read(buff);
if (n > 0) {
baos.write(buff, 0, n);
}
} while (n >= 0);
baos.close();
I've implemented a timeout mechanism as a workaround, and the data arrives
intact, albeit after a few thousand reads with 0 bytes returned.
--
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 63573] For some requests, ServletInputStream.read(byte[]
buffer) repeatedly returns 0 at EOF, fails to return -1
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63573
Remy Maucherat <re...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
--- Comment #1 from Remy Maucherat <re...@apache.org> ---
Please provide test code that fails for you using curl (or similar) to do the
post, and which does not use available(). It is possible available() returns 0,
and is basically a random value you should not care about since blocking IO is
used.
--
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 63573] For some requests, ServletInputStream.read(byte[]
buffer) repeatedly returns 0 at EOF, fails to return -1
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63573
Ferhat Savcı <fe...@cs.com.tr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEEDINFO |RESOLVED
--- Comment #2 from Ferhat Savcı <fe...@cs.com.tr> ---
Hi Remy,
I'll modify the code to copy streams using a fixed length buffer, will reopen
the issue if it comes back.
--
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