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

When returning a ResponseEntity with a Flux while the function is suspended, it fails to encode the body #27809

Closed
emilwihlander opened this issue Dec 13, 2021 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Milestone

Comments

@emilwihlander
Copy link

emilwihlander commented Dec 13, 2021

Affects: 5.3.13

When returning a ResponseEntity<Flux<[some class]>> when the function is suspended it unnests to Flux<[some class]> (tested: 5.3.13) while it previously unnested to [some class] (tested: 5.3.11).

Example

@RestController
class Controller(val service: SomeService) {
  @GetMapping("/")
  suspend fun getStrings(): ResponseEntity<Flux<ByteBuffer>> {
    val strs: Flux<String> = service.getStrings()
    // some coroutine function is called
    val headers = HttpHeaders()
    // Set headers
    return ResponseEntity.ok().headers(headers).body(strs)
  }
}

/**
 * <= 5.3.11
 * This worked fine
 * 
 * 5.3.13
 * Throws:
 * org.springframework.http.converter.HttpMessageNotWritableException: No Encoder for [reactor.core.publisher.Flux<java.nio.ByteBuffer>] with preset Content-Type 'application/octet-stream'
 **/

This is due to the change in org.springframework.web.reactive.result.method.annotation.ResponseEntityResultHandler, where the function handleResult was changed to handle coroutinescommit. It runs nested once instead of twice, as it did before.

Mixing reactor and coroutines is bad practice, I'd guess. Therefore, I'm not certain what the desired behaviour is. Any thoughts?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 13, 2021
@rrittwag
Copy link

rrittwag commented Dec 16, 2021

This small project provides an example. It passes a Flux<DataBuffer> from GridFS to ResponseEntity.body.

The unit test works when using Spring Boot 2.5.5 (Spring Framework 5.3.11), but fails on above versions.

@rstoyanchev rstoyanchev added theme: kotlin An issue related to Kotlin support in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 6, 2022
@rstoyanchev rstoyanchev added this to the Triage Queue milestone Jan 6, 2022
@rstoyanchev rstoyanchev modified the milestones: Triage Queue, 5.3.16 Feb 1, 2022
@rstoyanchev rstoyanchev added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 1, 2022
@sdeleuze sdeleuze modified the milestones: 5.3.16, 5.3.17 Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

6 participants