Bug 64944

Summary: Incorrect bytesSent metric when compression is enabled
Product: Tomcat 9 Reporter: chenrui
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 9.0.39   
Target Milestone: -----   
Hardware: PC   
OS: Linux   

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.