Skip to content

spring-webflux filters don't pass CoroutineContext #26977

Closed
@Ghostleg

Description

@Ghostleg

Affects: spring-webflux 5.3.7

I write my filter, pass some parameters to coroutine context via witchContext and want to be able use it later in the child coroutines and handlers. The problem is that CoroutineContext is lost in filter chain.

For example something like this

    @Bean
    fun testRouter(tracingFilter: ITracingFilter) = coRouter {
        GET("/test") { request ->
            val span = coroutineContext[SpanContext] //  is null
            someHandler.processRequest()
        }
        filter{ serverRequest, suspendFunction ->
            withContext(SpanContext()) {
                suspendFunction.invoke(serverRequest)
            }
        }
    }

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions