https://bz.apache.org/bugzilla/show_bug.cgi?id=70390
Bug ID: 70390
Summary: HTTP/2: client cancelling a request with a
gzip-compressed response closes the whole connection
Product: Tomcat 11
Version: 11.0.29
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P2
Component: Connectors
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: -------
Created attachment 40318
--> https://bz.apache.org/bugzilla/attachment.cgi?id=40318&action=edit
Reproducer: Maven project (embedded Tomcat, one servlet, JDK HttpClient). Run
with: mvn -q compile exec:java
When a client resets an HTTP/2 stream (RST_STREAM CANCEL) whose response is
being compressed, Tomcat closes the whole connection instead of only that
stream. All other streams on the connection fail. Browsers report
ERR_HTTP2_PROTOCOL_ERROR for unrelated requests, typically after a page reload
cancels its in-flight requests.
Without compression, the same cancellation only ends the cancelled stream, as
expected.
Steps to reproduce (attached Maven project: embedded Tomcat, one servlet, JDK
HttpClient):
1. Connector with compression="on" and the HTTP/2 upgrade protocol.
2. A servlet that sleeps, writes a small JSON body and calls flushBuffer().
3. On one HTTP/2 connection: start one request that is not cancelled, start
nine requests with Accept-Encoding: gzip, and cancel those nine while the
servlet is still sleeping.
Run mvn -q compile exec:java (add -Dexec.args=nogzip for the control run,
-Dtomcat.version=... for another version).
Actual result: the request that was not cancelled fails with
java.io.EOFException: EOF reached while reading, because the server closed the
connection.
Expected result: it completes with HTTP 200, as it does in the control run
without Accept-Encoding: gzip.
Analysis (from reading the 11.0.27 and 11.0.29 sources):
1. After the client's reset, the servlet's flush fails and the stream's output
buffer is marked closed. This is reported as a CloseNowException, which is
handled at stream level.
2. StreamProcessor.finishResponse() then calls GzipOutputFilter.end(), which
calls compressionStream.finish() to write the gzip trailer.
3. That write reaches the closed stream buffer, which throws a plain
IOException ("Unable to write to stream once it has been closed").
4. AbstractProcessor treats a plain IOException as a connection-level error
(ErrorState.CLOSE_CONNECTION_NOW), so the connection is closed with GOAWAY.
Possible fix: in GzipOutputFilter.end(), catch the IOException from
compressionStream.finish() / close() and rethrow it as CloseNowException, so
that it stays a stream-level error. With that change the reproducer passes.
There may be a better place to handle it.
--
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]