Marcin Small-ski
Marcin Small-ski

Reputation: 171

Spring Webflux throws IOException for SSE

I've been trying to implement the Server Sent Events using Spring Webflux (2.1.1.RELEASE) and consume it in JavaScript App (Angular 7).

The problem is that anytime I use .close() method on the EventSource on the client it makes the server throw:

Error [java.io.IOException: An established connection was aborted by the software in your host machine] for HTTP GET "/price", but ServerHttpResponse already committed (200 OK)

The code is pretty straightforward:

@RestController("/price")
public class PriceController {

private final PriceProvider priceProvider;

public PriceController (PriceProvider priceProvider) {
    this.priceProvider = priceProvider;
}


@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Price> randomPrices () {
    return priceProvider.getPrices().log();
}

}

The Flux is created as follows:

Flux.interval(Duration.ofSeconds(1)).map(i -> randomPrice());

On the client side i was trying to use the native EventSource and the pollyfills but with the same result all the time. Here's the output:

Despite that the program seems to behave correctly, though my logs are full of these ugly errors. Is there any way to fix it or at least swallow the exception?

Upvotes: 3

Views: 5648

Answers (1)

Brian Clozel
Brian Clozel

Reputation: 59141

This looks a lot like SPR-17257. In this case, we're getting an IOException, which is hard to differentiate between a client going away and a remote exception if you're streaming data from another server.

SPR-17341 will try to address that in the Spring Framework 5.2 release, to be included in Spring Boot 2.2.

Upvotes: 2

Related Questions