gzlicanyi opened a new pull request, #555:
URL: https://github.com/apache/skywalking-java/pull/555
<!--
⚠️ Please make sure to read this template first, pull requests that
don't accord with this template
maybe closed without notice.
Texts surrounded by `<` and `>` are meant to be replaced by you, e.g.
<framework name>, <issue number>.
Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
-->
### Fix <bug description or the bug issue number or bug issue link>
- [x] Add a unit test to verify that the fix works.
- [x] Explain briefly why the bug exists and how to fix it.
- [x] Update the [`CHANGES`
log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
### problem
```
java.lang.RuntimeException: Can not do async finish for the span repeatedly.
at
org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan.asyncFinish(AbstractTracingSpan.java:332)
at
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v20x.HttpClientRequestInterceptor$2.accept(HttpClientRequestInterceptor.java:106)
at
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v20x.HttpClientRequestInterceptor$2.accept(HttpClientRequestInterceptor.java:94)
```
In addition, there is another question:
A NullPointerException is thrown when executing
enhanceCacheObject.getSendSpan() in the afterMethod() method of the
HttpClientRequestInterceptor class.
### Steps to reproduce
Using the following dependencies:
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
```
Using the WebClient in custom GlobalFilter.
### Causes
1. The HttpClient instance is a singleton, and the setting and retrieval of
EnhanceCacheObject are not thread-safe. Therefore, the EnhanceCacheObject
obtained in the afterMethod may not necessarily be set by the same thread in
the beforeMethod.
2. HttpClient is used in WebClient scenarios, rather than in
NettyRoutingFilter scenarios, where ContextManager is inactive. So,
enhanceCacheObject may be null.
3. `responseMono.doAfterSuccessOrError` method may be executed multiple
times.
4. If an exception is thrown inside the accept method of
responseMono.doAfterSuccessOrError, it may disrupt the ongoing business process.
### how to fix it
1. Store the EnhanceCacheObject in a ThreadLocal.
2. To enhance code robustness
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]