-
Notifications
You must be signed in to change notification settings - Fork 38k
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
Propagate CoroutineContext
in CoWebFilter
#27522
Comments
To give you another example, Being able to customize the context makes it much easier to propagate MDCs and Brave's Tracing. Please consider it. |
This would be very helpful in regards to MDC context as mentioned above. I would be happy to put together a PR if any of the team members can point me in a direction that might be suitable to put this configuration? |
Yes. This is very ver helpful for kotlin coroutine user. |
Invoking suspend functions with customized CoroutineContext has been implemented, but there's no way to provide it currently. |
@2hyjun This feature is not implemented. That commit only added new invokeSuspendingFunction that accepts CoroutineContext. To implement this feature, InvocableHandlerMethod must be fixed to use new invokeSuspendingFunction and CoroutinesDispatchersProvider should be added. Lines 139 to 145 in 983c6e2
|
@rstoyanchev @be-hase Can we discuss about design of CoroutinesDispatchersProvider? If there is an agreement on the design, I am willing to write a PoC PR. |
@wplong11 |
It should be a |
Let's try to see if we can leverage |
Thank you. |
CoroutineContext
in CoWebFilter
|
To avoid compilation errors in Eclipse which does not support Java code dependency on Kotlin code. See spring-projectsgh-27522
Looks like with this implementation always the coroutine context of the last filter is winning. |
Please create a new dedicated issue with a reproducer if you think there is something to refine/fix. |
Uses latest Spring Framework 6.1 snapshots that propagate CoroutineContext in CoWebFilter[1]. [1] spring-projects/spring-framework#27522
Motivation
There are cases where the coroutine dispatcher is changed when performing blocking processing.
But now WebFlux uses Unconfined dispatcher.
https://github.com/spring-projects/spring-framework/blob/5.3.x/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java#L74
So once we change the dispatcher, subsequent processing will also be executed by that dispatcher.
For example, in the following example, it will be executed by blockingExecutor thread even after withContext.
We can work around this issue by using the default dispatcher instead of the Unconfined dispatcher.
However, writing
withContext(Dispatchers.Default)
on all controller methods can be tedious.So I want to be able to change the coroutine dispatcher used by WebFlux.
How
How about making it possible to change by registering a class such as CoroutinesDispatchersProvider in the bean?
For example, a framework called armeria allows we to specify a dispatcher
https://armeria.dev/docs/server-annotated-service#coroutine-dispatcher
The text was updated successfully, but these errors were encountered: