Skip to content

Investigate premature OutputBuffer recycling in Tomcat transport with AsyncContext #12540

@becomeStar

Description

@becomeStar

Follow-up investigation for #12524.

Symptom

When running tests with Tomcat 10 Embedded, we encounter java.lang.IllegalStateException: The output buffer object has been recycled and is no longer associated with this facade.
This indicates that the OutputBuffer is being accessed after Tomcat has recycled it.

Root Cause Analysis (Preliminary)

It seems related to Tomcat 10's RECYCLE_FACADES optimization. The facade object (specifically the underlying OutputBuffer) appears to be recycled prematurely—likely as soon as the initial servlet request handler returns—even though gRPC is still using the AsyncContext to write the response stream asynchronously.

Current Workaround

We have disabled facade recycling (setDiscardFacades(false)) in the test environment to prevent flakiness (See PR #12530).

Goal

Investigate if gRPC's usage of AsyncContext needs adjustment to be compatible with Tomcat's facade recycling logic, or if this is an issue with Tomcat's behavior in async scenarios.

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions