Skip to content
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

The result of Kotlin suspend fun cannot be received from @AfterReturning in spring boot 3.2.x version. #33072

Closed
ysj926 opened this issue Jun 20, 2024 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid theme: kotlin An issue related to Kotlin support

Comments

@ysj926
Copy link

ysj926 commented Jun 20, 2024

Affects:

  • org.springframework.boot: 3.2.5
  • org.springframework: 6.1.6
  • kotlin: 1.9

After calling the suspend func, we are post-processing the response (ex logging,...) through @AfterReturning.

Until spring boot version 3.1.12, we were able to receive and process returning value as desired.

However, when we upgraded the version to 3.2.x (and even 3.3.x), an issue occurred where MonoOnErrorResume was returned as a returning value.

    @AfterReturning("execution(* x.x.x.suspendFun(..))", returning = "response")
    fun controllerSuccessLogging(joinPoint: JoinPoint, response: Any) {
        logger.info("$response")
    }

When looking at the log flow, it seems that starting from 3.2.x, the @AfterReturning part is executed before the target function ends.

boot 3.1.12

[2024-06-20 14:34:46,181] [INFO] [http-nio-8080-exec-1] [RequestLoggingAspect] API [/v1/resource/test] PARAMS [GetTestRequest(abc=123)]
[2024-06-20 14:34:46,184] [INFO] [http-nio-8080-exec-1] [MySQLExceptionHandleAspect] [SQL] info(statement=query.selResource.selectInfo parameter={abc=23} )
[2024-06-20 14:34:46,288] [INFO] [http-nio-8080-exec-1] [RequestLoggingAspect] GetTestResponse(result=ok) <-- works as intended

boot 3.2.5

[2024-06-20 14:31:52,967] [INFO] [http-nio-8080-exec-1] [RequestLoggingAspect] API [/v1/resource/test] PARAMS [GetTestRequest(abc=123)]
[2024-06-20 14:31:52,968] [INFO] [http-nio-8080-exec-1] [RequestLoggingAspect] MonoOnErrorResume  <-- issue 
[2024-06-20 14:31:52,991] [INFO] [http-nio-8080-exec-1] [MySQLExceptionHandleAspect] [SQL] info(statement=query.selResource.selectInfo parameter={abc=23} )

Are there any changes to usage, or are there any parts where support has ended?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 20, 2024
@sdeleuze sdeleuze added theme: kotlin An issue related to Kotlin support in: core Issues in core modules (aop, beans, core, context, expression) labels Jun 20, 2024
@sdeleuze sdeleuze self-assigned this Jun 20, 2024
@sdeleuze
Copy link
Contributor

That's related to #22462 which turns suspending functions to Mono following the logic already implemented in the rest of the Coroutines support in Spring Framework.

I believe your former use case was working only when there was no invocation of suspending function in the body of your function, otherwise you would see COROUTINE_SUSPENDED printed (for example when invoking delay(...).

You should be able to log the return value with aspects defined like:

@Around("execution(* DemoController+.*(..))")
fun afterReturningAdvice(joinPoint: ProceedingJoinPoint): Any? {
    return (joinPoint.proceed(joinPoint.args) as Mono<Any>).doOnNext { println(it) }
}

So if I am not mistaken, the behaviour you see is expected.

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
@sdeleuze sdeleuze added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid theme: kotlin An issue related to Kotlin support
Projects
None yet
Development

No branches or pull requests

3 participants