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

Kotlin reactive apps using coroutines broken after upgrade to 3.0.4 #12914

Closed
und3rs opened this issue Mar 21, 2023 · 2 comments
Closed

Kotlin reactive apps using coroutines broken after upgrade to 3.0.4 #12914

und3rs opened this issue Mar 21, 2023 · 2 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: bug A general bug

Comments

@und3rs
Copy link

und3rs commented Mar 21, 2023

Describe the bug
I faced an error after upgrade spring boot from 3.0.1 to 3.0.4 on @PreAuthorize("hasRole('USER'").

To Reproduce

    @GetMapping("")
    @ResponseStatus(HttpStatus.OK)
    @PreAuthorize("hasRole('USER')")
    suspend fun something(): String {
        return "Hello"
    }

Error is..
The returnType class java.lang.Object on public java.lang.Object xxxx.xxxx.xxxx.xxxx.controller.XXXController.something(kotlin.coroutines.Continuation) must return an instance of org.reactivestreams.Publisher (for example, a Mono or Flux) in order to support Reactor Context

But if I change the code like this, works fine.

    @GetMapping("")
    @ResponseStatus(HttpStatus.OK)
    @PreAuthorize("hasRole('USER')")
    fun something(): Mono<String> {
        return Mono.just("Hello")
    }

Expected behavior
When I use spring boot 3.0.1, that any codes works fine.
But after I upgrade to 3.0.4, kotlin coroutines not work.

@und3rs und3rs added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Mar 21, 2023
@und3rs
Copy link
Author

und3rs commented Mar 21, 2023

I thinks the 'invoke' method in org.springframework.security.authorization.method.AuthorizationManagerBeforeReactiveMethodInterceptor should allow coroutine suspend function.

       @Override
	public Object invoke(MethodInvocation mi) throws Throwable {
		Method method = mi.getMethod();
		Class<?> type = method.getReturnType();
		Assert.state(Publisher.class.isAssignableFrom(type),
				() -> String.format("The returnType %s on %s must return an instance of org.reactivestreams.Publisher "
						+ "(for example, a Mono or Flux) in order to support Reactor Context", type, method));

@marcusdacoregio
Copy link
Contributor

Hi @und3rs, I'm marking this as a duplicate of #12080, but feel free to correct me if it appears to be a different issue.

@marcusdacoregio marcusdacoregio added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2023
@marcusdacoregio marcusdacoregio self-assigned this Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants