https://bz.apache.org/bugzilla/show_bug.cgi?id=62635
Bug ID: 62635
Summary: Async servlet over HTTP/2 response.flushBuffer()
intermittently fails
Product: Tomcat 9
Version: 9.0.x
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Servlet
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: -----
Sorry to bug you again. Now we were almost there, just had some failures
occasionally.
Test case:
import java.io.IOException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/asyncflush"}, asyncSupported = true)
public class AsyncFlush extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws IOException {
final AsyncContext asyncContext = request.startAsync();
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/binary");
final ServletOutputStream output = response.getOutputStream();
output.setWriteListener(new WriteListener() {
int j;
byte[] bytes = new byte[1000];
int expectedBytesSentOut;
@Override
public void onWritePossible() throws IOException {
System.out.println("onWritePossible called");
if (j > 2000) {
System.out.println("complete");
System.out.println("expected bytes sent out: " +
expectedBytesSentOut);
asyncContext.complete();
return;
}
while(output.isReady()) {
if (j % 5 == 4) {
System.out.println("start flush, j = " + j);
response.flushBuffer();
System.out.println("end flush, j = " + j);
} else {
System.out.println("start write, j = " + j);
output.write(bytes);
expectedBytesSentOut += 1000;
System.out.println("end write, j = " + j);
}
j++;
}
System.out.println("output.isReady() = " + false);
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
});
}
}
Run the client command:
$ nghttp "http://0.0.0.0:8080/asyncflush" -v
The flush operation hangs up.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]