Bug 64944 - Incorrect bytesSent metric when compression is enabled
Summary: Incorrect bytesSent metric when compression is enabled
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.39
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2020-11-30 06:27 UTC by chenrui
Modified: 2020-11-30 13:11 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description chenrui 2020-11-30 06:27:56 UTC
I'm using Spring Boot 2.2.11 with Tomcat 9.0.39. I found when compression is enabled, the bytesSent metric exposed by org.apache.coyote.RequestGroupInfo is always 0. Those metrics are exposed in JMX as well.

I believe the issue is caused by org.apache.coyote.http11.filters.GzipOutputFilter.doWrite(ByteBuffer) implementation. It doesn't change the chunk parameter position in this code branch:

    if (chunk.hasArray()) {
        compressionStream.write(chunk.array(), chunk.arrayOffset() +  chunk.position(), len);

So org.apache.coyote.Response.doWrite(ByteBuffer) method will not be able to update contentWritten correctly:

    contentWritten += len - chunk.remaining();
Comment 1 Mark Thomas 2020-11-30 13:11:45 UTC
Thanks for the report and the analysis.

Fixed in:
- 10.0.x for 10.0.0-M11 onwards
- 9.0.x for 9.0.41 onwards
- 8.5.x for 8.5.61 onwards

7.0.x was not affected.