Context propagation does not work correctly
be-hase opened this issue · comments
Expected Behavior
When using webflux client with reactor-netty as the foundation, context propagation is not working correctly within doOnSuccess when I write the following code.
( I am using Hooks.automaticContextPropagation
. )
webClient.get().uri("https://example.com").retrieve().toBodilessEntity()
.doOnSuccess {
log.info("doOnSuccess. MDC={}, myThreadLocal={}", MDC.getCopyOfContextMap(), myThreadLocal.get())
}
.block()
Normally, myThreadLocal
always should have a value, but it is null.
e.g.
Request. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=b56a985ebe16e3d6}, myThreadLocal=887c802d-0e0a-4398-82fc-325584e6e5a5
Response. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=eac8c2a04a688c53}, myThreadLocal=887c802d-0e0a-4398-82fc-325584e6e5a5
doOnSuccess. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=eac8c2a04a688c53}, myThreadLocal=null
The complete code is here.
https://github.com/be-hase/context-propagation-report-202309/tree/main/reactor-netty-issue
https://github.com/be-hase/context-propagation-report-202309/blob/main/reactor-netty-issue/src/main/kotlin/example/ReactorNettyIssueApplication.kt
It works with jdkClientHttpConnector, so I expect it is a reactor-netty issue.
Actual Behavior
myThreadLocal
always has a value.
Request. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=b56a985ebe16e3d6}, myThreadLocal=887c802d-0e0a-4398-82fc-325584e6e5a5
Response. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=eac8c2a04a688c53}, myThreadLocal=887c802d-0e0a-4398-82fc-325584e6e5a5
doOnSuccess. MDC={traceId=65112e6f3c6d3484b56a985ebe16e3d6, spanId=eac8c2a04a688c53}, myThreadLocal=887c802d-0e0a-4398-82fc-325584e6e5a5
Steps to Reproduce
Check out this repo( https://github.com/be-hase/context-propagation-report-202309 ), and run.
./gradlew :reactor-netty-issue:bootRun
Possible Solution
None
Your Environment
- Reactor version(s) used: 1.1.11
- Other relevant libraries versions (eg.
netty
, ...): 4.1.97 - JVM version (
java -version
): openjdk version "17.0.6" 2023-01-17 - OS and version (eg.
uname -a
): Darwin Kernel Version 22.5.0 - spring boot: 3.1.4
Duplicate of spring-projects/spring-framework#30273 and is being addressed via reactor/reactor-core#3478, please subscribe to that one.
Sorry, I didn't know there was a duplicate issue.
This issue is a duplicate, so it's ok to close it.