Bug 62569

Summary: Async servlet setReadListener does not work if post request data arrives much later than headers
Product: Tomcat 9 Reporter: Dapeng Zhang <zdapeng>
Component: ServletAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P2    
Version: 9.0.10   
Target Milestone: -----   
Hardware: PC   
OS: Linux   

Description Dapeng Zhang 2018-07-25 18:55:24 UTC
In async mode, servlet sets a ReadListener, and invokes onDataAvailable callbacks.
If a client first sends out a POST request headers, then 2 seconds later sends out the payload. The ReadListener callbacks will never be invoked, and the client never receives a response. Glassfish 5.0 does not have this issue. This may not be a serious problem for HTTP/1.1 and servlet 3.1, but it is a problem for HTTP/2 and servlet 4.0 because HTTP/2 is ful-duplex.

See the servlet code snippet in the Java EE tutorial example:
https://javaee.github.io/tutorial/servlets013.html

Client side command:

telnet localhost 8080

POST /asyncioservlet HTTP/1.1
Host: localhost
Content-Type: application/json
Transfer-Encoding: chunked

10
{"key1":"value"}
0
Comment 1 Mark Thomas 2018-08-07 15:48:35 UTC
This works for me. Note that the example is buggy - it does not handle the "-1" value returned by read when EOF is reached.
Comment 2 Dapeng Zhang 2018-08-07 17:09:05 UTC
My mistake. This does work. Sorry about that. But I do have some issues that ReadListener and WriteListener callbacks never get called when using http/2 (https://github.com/grpc/grpc-java/pull/4738). Will update once I find a easy way to reproduce it.