Search before asking
Apache SkyWalking Component
Java Agent (apache/skywalking-java)
What happened
try (CloseableHttpClient client = HttpAsyncClients.classic(
asyncClient, Timeout.ofSeconds(30))) {
String body = client.execute(
new HttpGet("http://127.0.0.1:8080/hello"),
response -> {
// This lambda is executed by the business thread that invokes `execute`.
return EntityUtils.toString(response.getEntity());
}
);
System.out.println(body);
}
When running the sample code with the SkyWalking Java Agent enabled, the HttpClient 5.x plugin may close the caller thread's active span unexpectedly.
The sample uses HttpAsyncClients.classic(...), which adapts an async HttpClient to the classic synchronous API. When the caller thread reads the response entity to EOF, HttpClient may invoke FutureCallback.completed() on that same caller thread.
The SkyWalking HttpClient 5.ugin wraps the callback in FutureCallbackWrapper. Its current implementation calls:
ContextManager.stopSpan(); without keeping a reference to the HTTP span created for this request.
Before reading the response body: TraceId is available
After reading the response body to EOF: TraceId becomes N/A
What you expected to happen
FutureCallback should only finish the span associated with the current HTTP request. It must not close the active span on the caller thread.
After reading the response body to EOF, the caller's Entry Span and TraceId should remain active until the business request actually completes.
How to reproduce
Please run the sample code included in the What happened section.
Anything else
No response
Are you willing to submit a pull request to fix on your own?
Code of Conduct
Search before asking
Apache SkyWalking Component
Java Agent (apache/skywalking-java)
What happened
When running the sample code with the SkyWalking Java Agent enabled, the HttpClient 5.x plugin may close the caller thread's active span unexpectedly.
The sample uses HttpAsyncClients.classic(...), which adapts an async HttpClient to the classic synchronous API. When the caller thread reads the response entity to EOF, HttpClient may invoke FutureCallback.completed() on that same caller thread.
The SkyWalking HttpClient 5.ugin wraps the callback in FutureCallbackWrapper. Its current implementation calls:
ContextManager.stopSpan(); without keeping a reference to the HTTP span created for this request.
Before reading the response body: TraceId is available
After reading the response body to EOF: TraceId becomes N/A
What you expected to happen
FutureCallbackshould only finish the span associated with the current HTTP request. It must not close the active span on the caller thread.After reading the response body to EOF, the caller's Entry Span and TraceId should remain active until the business request actually completes.
How to reproduce
Please run the sample code included in the What happened section.
Anything else
No response
Are you willing to submit a pull request to fix on your own?
Code of Conduct