java - Spring Cloud Gateway 使连接过早关闭

标签 java spring-boot spring-cloud netflix-ribbon spring-cloud-gateway

我在我的微服务设置中使用 spring cloud gateway 作为 API 网关,并使用 consul 作为服务发现。

在某些情况下,当某些微服务的 API 需要超过 2 分钟时,网关会抛出以下错误:

java.io.IOException: Connection closed prematurely
at reactor.ipc.netty.http.client.HttpClientOperations.onInboundClose(HttpClientOperations.java:269)
at reactor.ipc.netty.channel.ChannelOperationsHandler.channelInactive(ChannelOperationsHandler.java:113)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:420)
at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:377)
at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:342)
at io.netty.handler.codec.http.HttpClientCodec$Decoder.channelInactive(HttpClientCodec.java:282)
at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:223)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1429)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:947)
at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:822)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:313)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:745)

我多次尝试相同的 API,正好在 2 分钟后出现此错误。

有没有属性设置。 版本和依赖细节:

compile('org.springframework.cloud:spring-cloud-starter-consul-discovery')
compile('org.springframework.cloud:spring-cloud-starter-gateway')
compile('org.springframework.cloud:spring-cloud-starter-openfeign')


springBootVersion=2.0.3.RELEASE
springDMPVersion=1.0.4.RELEASE
springPlatformBomVersion=Cairo-SR2

功能区设置:

ribbon:
  ConnectTimeout: 3000
  ReadTimeout: 3000

最佳答案

下游服务出现问题。

在我的应用程序中,有一个 nodejs 应用程序在 spring 云网关后面运行,默认超时为 2 分钟。

引用:https://github.com/expressjs/express/issues/3330

在我的例子中,2 分钟后,nodejs 应用程序超时,这就是我在网关中收到错误的原因。

我通过更改节点应用程序中的超时值解决了这个问题

关于java - Spring Cloud Gateway 使连接过早关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53683273/

相关文章:

java - Java服务器中通过facebook登录验证用户身份

maven - 如何在spring boot中创建单个可执行文件war

java - Log4j 不会将所有日志保存到文件中

java - spring cloud端口号,让选择变得智能

spring-cloud - openfeign 2.1.1.RELEASE 中未找到 @EnableFeignClients

java - Spring Cloud承载头透传

java - 在 JButton 上设置多个图标

Java正在tomcat bin文件夹中创建文件

java - 在请求之间用 spring 保持状态

scala - 使用 Scala 读取 Spring Boot ConfigurationProperties