-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ThreadSPropagationChInterceptor for stacking #8735
Fix ThreadSPropagationChInterceptor for stacking #8735
Conversation
Related SO thread: https://stackoverflow.com/questions/77058188/multiple-threadstatepropagationchannelinterceptors-not-possible The current `ThreadStatePropagationChannelInterceptor` logic is to wrap one message to another (`MessageWithThreadState`), essentially stacking contexts. The `postReceive()` logic is to unwrap a `MessageWithThreadState`, therefore we deal with the latest pushed context which leads to the `ClassCastException` * Rework `ThreadStatePropagationChannelInterceptor` logic to reuse existing `MessageWithThreadState` and add the current context to its `stateQueue`. Therefore, the `postReceive()` will `poll()` the oldest context which is, essentially, the one populated by this interceptor before, according to the interceptors order * Fix `AbstractMessageChannel.setInterceptors()` to not modify provided list of interceptors * The new `ThreadStatePropagationChannelInterceptorTests` demonstrates the problem described in that mentioned SO question and verifies that context are propagated in the order they have been populated **Cherry-pick to `6.1.x` & `6.0.x`**
…e scenario. Essentially, copy the state queue to a new decorated message * Fix `BroadcastingDispatcher` to always decorate message, even if not `applySequence`
OK. Thinking about this one more time, I convince myself that this wrapping approach is not so good. Especially when we send the same message to several handlers like in case of publish-subscribe channel. We may still have this Probably that should be done as a new feature just for current version since it is a bit breaking change and this PR still makes sense as bug fix for previous version. |
* Fix ThreadSPropagationChInterceptor for stacking Related SO thread: https://stackoverflow.com/questions/77058188/multiple-threadstatepropagationchannelinterceptors-not-possible The current `ThreadStatePropagationChannelInterceptor` logic is to wrap one message to another (`MessageWithThreadState`), essentially stacking contexts. The `postReceive()` logic is to unwrap a `MessageWithThreadState`, therefore we deal with the latest pushed context which leads to the `ClassCastException` * Rework `ThreadStatePropagationChannelInterceptor` logic to reuse existing `MessageWithThreadState` and add the current context to its `stateQueue`. Therefore, the `postReceive()` will `poll()` the oldest context which is, essentially, the one populated by this interceptor before, according to the interceptors order * Fix `AbstractMessageChannel.setInterceptors()` to not modify provided list of interceptors * The new `ThreadStatePropagationChannelInterceptorTests` demonstrates the problem described in that mentioned SO question and verifies that context are propagated in the order they have been populated **Cherry-pick to `6.1.x` & `6.0.x`** * * Fix `ThreadStatePropagationChannelInterceptor` for publish-subscribe scenario. Essentially, copy the state queue to a new decorated message * Fix `BroadcastingDispatcher` to always decorate message, even if not `applySequence` * * Fix unused import in the `BroadcastingDispatcher` * * Fix unused import in the `ThreadStatePropagationChannelInterceptor`
* Fix ThreadSPropagationChInterceptor for stacking Related SO thread: https://stackoverflow.com/questions/77058188/multiple-threadstatepropagationchannelinterceptors-not-possible The current `ThreadStatePropagationChannelInterceptor` logic is to wrap one message to another (`MessageWithThreadState`), essentially stacking contexts. The `postReceive()` logic is to unwrap a `MessageWithThreadState`, therefore we deal with the latest pushed context which leads to the `ClassCastException` * Rework `ThreadStatePropagationChannelInterceptor` logic to reuse existing `MessageWithThreadState` and add the current context to its `stateQueue`. Therefore, the `postReceive()` will `poll()` the oldest context which is, essentially, the one populated by this interceptor before, according to the interceptors order * Fix `AbstractMessageChannel.setInterceptors()` to not modify provided list of interceptors * The new `ThreadStatePropagationChannelInterceptorTests` demonstrates the problem described in that mentioned SO question and verifies that context are propagated in the order they have been populated **Cherry-pick to `6.1.x` & `6.0.x`** * * Fix `ThreadStatePropagationChannelInterceptor` for publish-subscribe scenario. Essentially, copy the state queue to a new decorated message * Fix `BroadcastingDispatcher` to always decorate message, even if not `applySequence` * * Fix unused import in the `BroadcastingDispatcher` * * Fix unused import in the `ThreadStatePropagationChannelInterceptor`
...and cherry-picked. |
Related SO thread: https://stackoverflow.com/questions/77058188/multiple-threadstatepropagationchannelinterceptors-not-possible
The current
ThreadStatePropagationChannelInterceptor
logic is to wrap one message to another (MessageWithThreadState
), essentially stacking contexts. ThepostReceive()
logic is to unwrap aMessageWithThreadState
, therefore we deal with the latest pushed context which leads to theClassCastException
ThreadStatePropagationChannelInterceptor
logic to reuse existingMessageWithThreadState
and add the current context to itsstateQueue
.Therefore, the
postReceive()
willpoll()
the oldest context which is, essentially, the one populated by this interceptor before, according to the interceptors orderAbstractMessageChannel.setInterceptors()
to not modify provided list of interceptorsThreadStatePropagationChannelInterceptorTests
demonstrates the problem described in that mentioned SO question and verifies that context are propagated in the order they have been populatedCherry-pick to
6.1.x
&6.0.x