Skip to content

Pickup coroutineContext saved by CoWebFilter in coRouter #31793

Closed
@ilya40umov

Description

This was problem initially brought up here: micrometer-metrics/tracing#174 (comment) by @meberhard.

Problem: Currently the only place in Spring Framework that is picking up CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE is this: https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java#L296
but this code does not get executed for coRouter handlers. This means that the handlers installed by coRouter won't inherit the coroutineContext from CoWebFilter(s).

Known workarounds: you can add the look up into each instance of coRouter DSL manually:

coRouter {
    context { it.exchange().attributes[CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext }
    GET("/demo", demoHandler::demoCall)
}

To show case it, I have the following example:

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions