Why do I get `Only one connection receive subscriber allowed` when the response has an HTTP error status code?

Tobi :

Within a rest request I send another request to a webservice using Spring WebClient and want to return the result to the caller:

return webClient.post()
  .uri(url)
  .body(...)
  .retrieve()
  .bodyToMono(String::class.java)
  .map { ResponseEntity.ok(it) }

Now it that webservice returns a HTTP error status code I receive the following error:

java.lang.IllegalStateException: Only one connection receive subscriber allowed.

When a status 200 code is returned, no error is thrown.

I also tried checking the status and throwing an exception myself, but the behavior is still the same:

return webClient.post()
  .uri(url)
  .body(...)
  .retrieve()
  .onStatus(HttpStatus::isError) { clientResonse ->
     clientResonse.bodyToMono(String::class.java)
        .map { RuntimeException(it) }
  }
  .bodyToMono(String::class.java)
  .map { ResponseEntity.ok(it) }

What am I doing wrong?

The code samples are in Kotlin but I assume every Java dev can read it :)

Brian Clozel :

This is a known issue in Spring Framework and it's been fixed in Spring Framework 5.1.4 - see SPR-17564.

Unfortunately, I'm not aware of any workaround for this problem, so upgrading to Spring Framework 5.1.4 / Spring Boot 2.1.2 is the only solution so far.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=101725&siteId=1