admin管理员组文章数量:1608631
Spring Cloud Gateway Server 500 问题(已解决)
问题描述:启动服务的一段时间内,所有服务均正常运行,可以访问;然而过段时间后,出现500 Server Error 服务超时问题,报错截图如下:
原因分析:当时处于开发环境,前后端都在本地运行,后面由于之前的WIFI网络不好,切换成另一个WIFI(或手机热点),导致本地局域网IP发生变化,gateway无法再找到其所代理的服务(这些服务其实还在正常运行,能够通过localhost:服务port访问),我的gateway配置如下:
server:
port: 80 # 网关端口
spring:
application:
name: opentool-gateway # 服务名称
cloud:
nacos:
discovery:
server-addr: localhost:8848 # nacos地址
config:
# 配置中心地址
server-addr: localhost:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
gateway:
discovery:
locator:
enabled: true # 是否与服务注册于发现组件进行结合,通过 serviceId 转发到具体的服务实例。默认为 false
lowerCaseServiceId: true # 是将请求路径上的服务名配置为小写(因为服务注册的时候,向注册中心注册时将服务名转成大写的了)
routes: # 网关路由配置
- id: opentool-system # 路由id
uri: lb://opentool-system # 路由的目标地址 lb就是负载均衡,后面跟服务名称
predicates:
- Path=/user/**, /file/**, /oss/** # 按照路径匹配
- id: opentool-dashboard
uri: lb://opentool-dashboard
predicates:
- Path=/data-analysis/**,/workbench/**
- id: opentool-general-tool
uri: lb://opentool-general-tool
predicates:
- Path=/imageConvert/**,/imageEdit/**
- id: opentool-ai-tool
uri: lb://opentool-ai-tool
predicates:
- Path=/chatgpt/**
globalcors: # 全局的跨域请求
add-to-simple-url-handler-mapping: true # 解决options请求被拦截问题
cors-configurations:
'[/**]':
allowedOrigins: # 允许哪些网站的跨域请求
- "http://localhost:5173"
allowedMethods: # 允许的跨域ajax的请求方法
- "GET"
- "POST"
- "DELETE"
- "PUT"
- "OPTIONS"
allowedHeaders: "*" # 允许在请求中携带头信息
allowCredentials: true # 是否允许携带cookie信息
maxAge: 360000 # 这次跨域检测的有效期
httpclient:
pool:
# 在连接池中的空闲连接的最大空闲时间,默认60000ms,http.timeout默认为30000ms(要保证max-idle-time不大于connection-timeout)
max-idle-time: 20000ms
connect-timeout: 60000 # 连接超时时间,单位为毫秒,默认为30秒
response-timeout: 60000 # 响应超时时间,单位为毫秒,默认为30秒
可以看到,gateway在代理其它服务时用的lb(loadbalancer),个人猜测其它服务在注册到nacos把当时的局域网ip也一起注册上去了,导致lb在寻找服务时访问的还是之前网络ip的服务,但实际上现在服务的局域网ip已经改变了,也就导致了gateway以为其它服务挂掉了。
猜测的反向验证,既然如此,假如我把WIFI切回服务启动的那个WIFI,gateway能够再次发现其它服务的话,那就说明猜测是正确的(也不一定,可能是其它原理,有懂哥可以在评论区解释一下):
可以看到,切回原来wifi后,我的服务能够再次正常访问了!!!,这时候我们打开cmd,输入ipconfig,查看网络ip配置:
可以发现IPv4地址为10.20.1.114,这与一开始no further information: /10.20.1.114:8084中所显示的ip一致,再次验证猜测正确。
解决方法
- 网络切换:把网络切换回你服务启动时的WIFI
- 重启大法:把其它服务(gateway服务重启不重启都可以)全部重启,即可正常访问。
本文标签: ChannelAbstractChannelIONettytimed
版权声明:本文标题:io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further informa 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728549720a1163275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论