From 40d9eeeee30d62a263206acf2436463092fca52a Mon Sep 17 00:00:00 2001 From: earlgrey02 Date: Fri, 7 Jun 2024 00:05:52 +0900 Subject: [PATCH] Add explicit coroutine context to CoWebExceptionHandler --- .../springframework/web/server/CoWebExceptionHandler.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/kotlin/org/springframework/web/server/CoWebExceptionHandler.kt b/spring-web/src/main/kotlin/org/springframework/web/server/CoWebExceptionHandler.kt index 18069640a60c..ac70d4c66630 100644 --- a/spring-web/src/main/kotlin/org/springframework/web/server/CoWebExceptionHandler.kt +++ b/spring-web/src/main/kotlin/org/springframework/web/server/CoWebExceptionHandler.kt @@ -3,11 +3,13 @@ package org.springframework.web.server import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.reactor.mono import reactor.core.publisher.Mono +import kotlin.coroutines.CoroutineContext abstract class CoWebExceptionHandler : WebExceptionHandler { - final override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono = - mono(Dispatchers.Unconfined) { coHandle(exchange, ex) }.then() - + final override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono { + val context = exchange.attributes[CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext? + return mono(context ?: Dispatchers.Unconfined) { coHandle(exchange, ex) }.then() + } protected abstract suspend fun coHandle(exchange: ServerWebExchange, ex: Throwable) }