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

Spring Webflux suspend handler not working #34475

Open
FrontierPsychiatrist opened this issue Feb 24, 2025 · 1 comment
Open

Spring Webflux suspend handler not working #34475

FrontierPsychiatrist opened this issue Feb 24, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@FrontierPsychiatrist
Copy link

I am trying out the support for suspend handler functions as described in this part of the documentation. I've had great success in other projects using the coRouter DSL but wanted to see how it looks and feels when using suspend directly on handlers.

First of all I wanted to say that I found it a bit hard to understand in the linked documentation if suspend handlers are only for Spring Webflux or if they will also work in Spring MVC (basically the spring-boot-starter-web package).

Anyway, in neither case could I get them to work. I always get a NPE when the coroutine context is being accessed.

For Webflux:

2025-02-24T09:43:52.976+01:00 ERROR 97430 --- [ux-http-epoll-2] a.w.r.e.AbstractErrorWebExceptionHandler : [dc4ac96e-1]  500 Server Error for HTTP GET "/hello-suspend"

java.lang.NullPointerException: null
	at kotlin.coroutines.jvm.internal.ContinuationImpl.getContext(ContinuationImpl.kt:105) ~[kotlin-stdlib-2.1.10.jar:2.1.10-release-473]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ HTTP GET "/hello-suspend" [ExceptionHandlingWebHandler]
Original Stack Trace:
		at kotlin.coroutines.jvm.internal.ContinuationImpl.getContext(ContinuationImpl.kt:105) ~[kotlin-stdlib-2.1.10.jar:2.1.10-release-473]
		at kotlin.coroutines.jvm.internal.ContinuationImpl.intercepted(ContinuationImpl.kt:112) ~[kotlin-stdlib-2.1.10.jar:2.1.10-release-473]
		at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.intercepted(IntrinsicsJvm.kt:182) ~[kotlin-stdlib-2.1.10.jar:2.1.10-release-473]
		at kotlinx.coroutines.DelayKt.delay(Delay.kt:172) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
		at com.example.app.Controller.getHello(Controller.kt:14) ~[main/:na]
		[... abbreviated]
		at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]

I hope I have not overlooked something simple. I tried to play around with dependencies and versions, but it never worked. I have attached a demo application with a test that fails.

Thank you for your support.

@FrontierPsychiatrist
Copy link
Author

I think attaching the demo failed, so doing that again: suspend-handler-failing.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

2 participants