Spring Reactive:java.io.IOException:当我关闭连接时,主机中的软件中止了已建立的连接 [英] Spring Reactive: java.io.IOException: An established connection was aborted by the software in your host machine, when I close the connection

查看:80
本文介绍了Spring Reactive:java.io.IOException:当我关闭连接时,主机中的软件中止了已建立的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 spring 反应式应用程序,我创建了一个休息服务,它每秒产生一个事件.我的休息控制器的代码是:

Working with spring reactive application, I created a rest service which produces an event every second. The code for my rest controller is:

@GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Event> getEvents() {
    Flux<Event> eventFlux = Flux.fromStream(Stream.generate(() -> new Event(new Random().nextLong(), "Hello Event")));
    Flux<Long> emmitFlux = Flux.interval(Duration.ofSeconds(1));
    return Flux.zip(eventFlux, emmitFlux).map(Tuple2::getT1);
}

应用程序在浏览器中的 url: localhost:8080/events 上运行良好.我每秒都会收到一个新事件.但是当我关闭浏览器时,我收到以下错误:

The application runs fine at the url: localhost:8080/events in the browser. I get a new event every second. But when I close the browser I get the following error:

java.io.IOException: An established connection was aborted by the software in your host machine

有没有人遇到并解决过与 spring-reactive 类似的问题?

Have anyone faced and resolved any similar issue with spring-reactive?

推荐答案

您看到此消息是因为 Spring WebFlux 没有正确的方法来区分常规 SSE 流取消和由于网络连接问题导致的意外连接关闭.

You see this message because Spring WebFlux has no proper way to differentiate a regular SSE stream cancellation from a unexpected connection closing due to network connectivity issue for example.

>

我们甚至过滤了一些典型的消息,比如管道损坏",但我猜你在 Windows 上并且异常消息是本地化的,所以我们不能以可靠的方式做到这一点.

We even filter some typical messages like "broken pipe", but I guess you are on windows and exception messages are localized so we can't do that in a reliable way.

这作为 SPR-16688 的一部分,将于春季推出Framework 5.0.6/Spring Boot 2.0.2,我们改进了此类用例的日志记录,以使其更相关:

That said as part of SPR-16688 which will be available as of Spring Framework 5.0.6 / Spring Boot 2.0.2, we have improved the logging for such use case in order to make it more relevant:

  • Reactor Netty 除了抛出错误之外不会记录错误例外,请参阅 reactor-netty#339
  • WebFlux 服务器现在使用警告错误日志级别而不是错误
  • 在日志中只打印消息,而不是在响应式世界中几乎无用的堆栈跟踪

这篇关于Spring Reactive:java.io.IOException:当我关闭连接时,主机中的软件中止了已建立的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆