You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prevent servlet snippet injection from corrupting recycled responses - #21104
copilot/task-fix-snippet-injection-issueopen-telemetry/opentelemetry-java-instrumentation:copilot/task-fix-snippet-injection-issueCopy head branch name to clipboard
copilot/task-fix-snippet-injection-issueopen-telemetry/opentelemetry-java-instrumentation:copilot/task-fix-snippet-injection-issueCopy head branch name to clipboard
Prevent recycled Jetty output streams from carrying stale snippet state into later requests. A cached five-byte Content-Length could truncate a 228-byte JSP to 37 bytes.
Scope stream state to the request lifetime in both javax and jakarta instrumentation, while keeping stream and writer matching independent and preserving late content-type support.
CopilotAI
changed the title
[WIP] Fix advice failure with snippet injection in Jetty smoke tests
Prevent servlet snippet injection from corrupting recycled responses
Oct 31, 2026
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Mock lifetime and synchronous keep-alive tests do not establish shared-body lifecycle behavior when forwards or async code reset the raw container response, so installed-agent validation is needed.
No open issues 🎉
What changed in this PR
This PR fixes servlet snippet injection state leaking across recycled responses, preventing stale Content-Length values from truncating later responses in both javax and jakarta instrumentation.
Changes:
Bind injection state to the request and response body while preserving async redispatch and late-content-type support.
Share writer and stream tracking, and reset abandoned body state without double-adjusting Content-Length.
Add lifecycle regression tests and a Jetty smoke test that reuses one HTTP/1.1 connection.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Both servlet response wrappers disable stream injection before writer creation succeeds, causing snippet injection to be lost when callers catch a getWriter() failure and continue using the output stream.
[Testing] The new ERROR-dispatch behavior lacks an installed-agent regression: the unit test constructs the wrapper directly, leaving its interaction with the existing-wrapper guard and reset advice untested. Add a regression for both Servlet 3 and Servlet 5 that writes an uncommitted fixed-length body, dispatches to an HTML error servlet, and checks the complete replacement body, exactly one snippet, and matching Content-Length when present. The same gap applies to Servlet5SnippetInjectingResponseWrapper.java:66.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An unpublished finding about stale cached writers after raw async response resets warrants human assessment because it can bypass container ownership checks and disable active-stream injection.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because an unpublished finding identifies an asynchronous span-export race that may contaminate subsequent tests and undermine their assertions.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Both servlet versions unnecessarily clear an already-empty virtual field on every output-stream write, adding volatile-write overhead even when snippet injection is disabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent recycled Jetty output streams from carrying stale snippet state into later requests. A cached five-byte Content-Length could truncate a 228-byte JSP to 37 bytes.
Scope stream state to the request lifetime in both javax and jakarta instrumentation, while keeping stream and writer matching independent and preserving late content-type support.
Fixes #21096.