WebClient MDC data not propagated
See original GitHub issueEnvironment Details
- Helidon Version: 2.4.2
- Helidon SE
- JDK version: 11
- OS: Windows/Linux/Mac
- Docker version (if applicable): able to reproduce in local as well as docker
Problem Description
Scenario : When Webserver Receives 1st request and does an Webclient call during Processing and Context is propagated Correctly
When Webserver Receives 2nd request and does an Webclient call during Processing , previous Webclient Context (1st one) is propagated post the Weblient call and the processing post that call is having context from previous call
Current Behavior : From 2nd Call onwards 1st call’s Context is getting propogated post webclient call Expected Behavior : Webclient call should propagate the Current Call Context without switching to first call’s context
It can be easily reprodcued
Logs:
2022.03.31 15:41:56 FINE io.helidon.webserver.NettyWebServer$NettyLog Thread[nioEventLoopGroup-2-1,10,main]: [id: 0xede758a3, L:/0:0:0:0:0:0:0:0:8080] READ: [id: 0x74bb5d69, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:60235] 2022.03.31 15:41:56 FINE io.helidon.webserver.NettyWebServer$NettyLog Thread[nioEventLoopGroup-2-1,10,main]: [id: 0xede758a3, L:/0:0:0:0:0:0:0:0:8080] READ: [id: 0x27dd2624, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:60236] 2022.03.31 15:41:56 FINE io.helidon.webserver.NettyWebServer$NettyLog Thread[nioEventLoopGroup-2-1,10,main]: [id: 0xede758a3, L:/0:0:0:0:0:0:0:0:8080] READ COMPLETE 2022.03.31 15:41:56 FINE io.netty.buffer.AbstractByteBuf Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.buffer.checkAccessible: true 2022.03.31 15:41:56 FINE io.netty.buffer.AbstractByteBuf Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.buffer.checkBounds: true 2022.03.31 15:41:56 FINE io.netty.util.ResourceLeakDetectorFactory Thread[nioEventLoopGroup-3-2,10,main]: Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@4f79c007 2022.03.31 15:41:56 FINE io.netty.util.Recycler Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.recycler.maxCapacityPerThread: 4096 2022.03.31 15:41:56 FINE io.netty.util.Recycler Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.recycler.ratio: 8 2022.03.31 15:41:56 FINE io.netty.util.Recycler Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.recycler.chunkSize: 32 2022.03.31 15:41:56 FINE io.netty.util.Recycler Thread[nioEventLoopGroup-3-2,10,main]: -Dio.netty.recycler.blocking: false 2022.03.31 15:41:56 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-1,10,main]: [Handler: 1746738214, Channel: 0x74bb5d69] Read complete not lastContent 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpRequest: 1027168240. Remote address: /0:0:0:0:0:0:0:1:60236. Scope id: web-1:1 Setting Namespace : 01 MDC_NAMESPACE_KEY After set: Optional[01] 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpContent: 1673502283 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpContent: 1110988450 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received LastHttpContent: 1110988450 MDC_NAMESPACE_KEY: Optional[01] 2022.03.31 15:41:57 INFO org.example.GreetService Thread[nioEventLoopGroup-3-2,10,main]: Initial Namespace in processMessageHandler map :01 MDC_NAMESPACE_KEY: Optional[01] 2022.03.31 15:41:57 INFO org.example.GreetService Thread[nioEventLoopGroup-3-2,10,main]: Namespace in webclientCall :01 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Read complete lastContent 2022.03.31 15:41:57 FINE io.helidon.webserver.NettyWebServer$NettyLog Thread[nioEventLoopGroup-2-1,10,main]: [id: 0xede758a3, L:/0:0:0:0:0:0:0:0:8080] READ: [id: 0x3faa0467, L:/127.0.0.1:8080 - R:/127.0.0.1:60239] 2022.03.31 15:41:57 FINE io.helidon.webserver.NettyWebServer$NettyLog Thread[nioEventLoopGroup-2-1,10,main]: [id: 0xede758a3, L:/0:0:0:0:0:0:0:0:8080] READ COMPLETE 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received HttpRequest: 1299183979. Remote address: /127.0.0.1:60239. Scope id: web-1:2 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Read complete has requests: io.helidon.webserver.RequestContext@66409399 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received HttpContent: 1932320011 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received HttpContent: 93927352 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received LastHttpContent: 93927352 2022.03.31 15:41:57 FINE io.netty.handler.codec.compression.Brotli Thread[helidon-client-0,10,main]: brotli4j not in the classpath; Brotli support will be unavailable. 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Response complete: 1299183979 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Read complete lastContent MDC_NAMESPACE_KEY: Optional[01] 2022.03.31 15:41:57 INFO org.example.GreetService Thread[helidon-client-0,10,main]: Namespace post Webclient Call in processMessageHandler accept :01 2022.03.31 15:41:57 INFO org.example.GreetService Thread[helidon-client-0,10,main]: { "status": "Success" } 2022.03.31 15:41:57 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Response complete: 1027168240 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpRequest: 77709676. Remote address: /0:0:0:0:0:0:0:1:60236. Scope id: web-1:3 Setting Namespace : 02 MDC_NAMESPACE_KEY After set: Optional[02] 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpContent: 1725809056 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Read complete has requests: io.helidon.webserver.RequestContext@e2e56ae 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received HttpContent: 68045990 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Received LastHttpContent: 68045990 MDC_NAMESPACE_KEY: Optional[02] 2022.03.31 15:42:09 INFO org.example.GreetService Thread[nioEventLoopGroup-3-2,10,main]: Initial Namespace in processMessageHandler map :02 MDC_NAMESPACE_KEY: Optional[02] 2022.03.31 15:42:09 INFO org.example.GreetService Thread[nioEventLoopGroup-3-2,10,main]: Namespace in webclientCall :02 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Read complete lastContent 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received HttpRequest: 1486904527. Remote address: /127.0.0.1:60239. Scope id: web-1:4 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Read complete has requests: io.helidon.webserver.RequestContext@57698351 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received HttpContent: 1591854374 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Received LastHttpContent: 1591854374 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Response complete: 1486904527 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-3,10,main]: [Handler: 141393570, Channel: 0x3faa0467] Read complete lastContent MDC_NAMESPACE_KEY: Optional[01] 2022.03.31 15:42:09 INFO org.example.GreetService Thread[helidon-client-0,10,main]: Namespace post Webclient Call in processMessageHandler accept :01 2022.03.31 15:42:09 INFO org.example.GreetService Thread[helidon-client-0,10,main]: { "status": "Success" } 2022.03.31 15:42:09 FINE io.helidon.webserver.ForwardingHandler Thread[nioEventLoopGroup-3-2,10,main]: [Handler: 1110999505, Channel: 0x27dd2624] Response complete: 77709676
Steps to reproduce
Sample Code Link : https://github.com/vamseeds/HelidonContextPropagation Steps to reproduce : Call 1 : http://localhost:8080/01/message (Can see the current Context logs) Call 2 : http://localhost:8080/02/message (Will start seeing Call 1 logs post Webclient Call)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
A workaround for this is to manually propagate the MDC data using context. E.g. In your filter do something like this:
In the webclient response callback:
I was able to fix this in master with the following changes: