Repository navigation
Conversation
The async callback read the response from the application's HttpContext before the future result. An application can share one context across concurrent requests, so that attribute can hold another in-flight exchange's response: the span got the wrong status and header tags, and reading headers while the other exchange modified them threw IndexOutOfBoundsException. Prefer the response carried by the future result (an HttpResponse or the head of a Message), and fall back to the context only when the result carries none, as on failure or cancellation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
Direct responses and Message response heads take precedence over a shared HttpContext, preventing another exchange’s response from overriding them while retaining fallback for results without a response.
🤖 Bits Code Review · Commit 9e21f70
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
| private static HttpContext contextWith(HttpResponse response) { | ||
| HttpContext context = new BasicHttpContext(); | ||
| context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); | ||
| return context; | ||
| } |
There was a problem hiding this comment.
nit, optional, can be in follow up: maybe make sense to have a builder to create context in fluent way: retrun builder.setA().setB().setC().build(); ?
| @Nullable | ||
| static HttpResponse extractHttpResponse( | ||
| @Nullable Object futureResult, @Nullable HttpContext context) { | ||
| if (futureResult instanceof HttpResponse) { |
There was a problem hiding this comment.
A custom AsyncResponseConsumer<HttpResponse> can return a synthesized response. For example, if the server sends 404 and the consumer returns a new BasicHttpResponse(200), this branch makes the span report 200 even when the request has its own context containing the original 404. I verified that the selector returns 404 on the base and 200 on this head. Could we capture the exchange response before the consumer transforms it and add a regression test for this case?
--- found with Codex
| * Returns the response of this exchange, preferring the one carried by the future result. | ||
| * | ||
| * <p>The context is supplied by the application and may be shared across concurrent requests, in | ||
| * which case its response attribute can belong to another in-flight exchange. It is only used |
There was a problem hiding this comment.
Could we qualify the PR summary to cover results that carry an HTTP response? This fallback still reads the shared context on cancellation, failure, or a body-only result. For example, if A is cancelled before receiving a response and B has already stored a 503 in the shared context, A's span can still report B's 503.
--- found with Codex
AlexeyKuznetsov-DD
left a comment
There was a problem hiding this comment.
LGTM, left couple of comments found by me and codex
What Does This Do
Makes Apache HttpClient 5 async client spans take their status code and response header tags from their own response. Before, when the application shared one
HttpContextacross concurrent requests, a span could report another in-flight request's response.Motivation
The async callback read the response from the application-supplied
HttpContextfirst, and used the future's own result only as a fallback. A context reused across concurrentexecutecalls holds whichever exchange most recently setHTTP_RESPONSE, so:IndexOutOfBoundsExceptionfromHeaderGroup.getFirstHeader, reported as "Failed to decorate span on response"The read order dates back to the original async instrumentation. It only became visible in instrumentation telemetry once #12017 made
onResponseexception-safe and logged the failure. Before that, the exception escaped the callback, so the span was never finished and the application's callback never ran.Additional Notes
HttpResponse(e.g.SimpleHttpResponse), or the head of aMessage<HttpResponse, ?>(e.g.BasicResponseConsumer). The context is only a fallback when the result carries no response, such as on failure, cancellation or custom consumers.Messageexists since httpcore5 5.0, so the muzzle range is unchanged.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issue🤖 Generated with Claude Code