spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.49k stars 3.31k forks source link

Connection refused #2972

Closed michaelwangwangwang closed 5 months ago

michaelwangwangwang commented 1 year ago

When a service instance suddenly goes down, the gateway sometimes has a 500 error, but the gateway itself has the function of automatic routing retry, I don’t know why the retry does not take effect sometimes。

the error is as follows:

AbstractErrorWebExceptionHandler|[aa7fd694-95055961] 500 Server Error for HTTP POST "/xxx-xx-xxx/queryData"
io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /xx,xx,xxx:8080
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ springfox.boot.starter.autoconfigure.SwaggerUiWebFluxConfiguration$CustomWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/xxx-xxx-xx-x/queryData" [ExceptionHandlingWebHandler]
Stack trace:
Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[netty-transport-native-unix-common-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.channel.unix.Socket.finishConnect(Socket.java:251) ~[netty-transport-native-unix-common-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:673) [netty-transport-native-epoll-4.1.54.Final-linux-x86_64.jar!/:4.1.54.Final]
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:650) [netty-transport-native-epoll-4.1.54.Final-linux-x86_64.jar!/:4.1.54.Final]
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:530) [netty-transport-native-epoll-4.1.54.Final-linux-x86_64.jar!/:4.1.54.Final]
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:470) [netty-transport-native-epoll-4.1.54.Final-linux-x86_64.jar!/:4.1.54.Final]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) [netty-transport-native-epoll-4.1.54.Final-linux-x86_64.jar!/:4.1.54.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-common-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.54.Final.jar!/:4.1.54.Final]
at java.lang.Thread.run(Thread.java:834) [?:?]
michaelwangwangwang commented 1 year ago

the version of the springboot and gateway are as follows:

springboot version:2.5.12 springCloud gateway:3.0.6

and the gateway configuration is as follows:

server: 
  port: 80
spring:
  application: 
    name: spring-cloud-gateway 
  cloud: 
    loadbalancer: 
      cache: 
        enabled: true
      retry: 
        enabled: true
        retry-on-all-operations: true
        max-retries-on-same-service-instance: 0
        max-retries-on-next-service-instance: 3
    gateway: 
      discovery: 
        locator: 
          enabled: true
          lowerCaseServiceId: true
          'predicates[0]': 
            name: Path
            args: 
              patterns: '''/'' + serviceId + ''/**'''
          'filters[0]': 
            name: RewritePath
            args: 
              regexp: '''/'' + serviceId + ''/(?<remaining>.*)'''
              replacement: '''/$\{remaining}'''
          'filters[1]': 
            name: Retry
            args: 
              retries: 3
              exceptions: 
                '[0]': '''java.net.ConnectException'''
                '[1]': '''java.io.IOException'''
              statuses: 
                '[0]': '''BAD_GATEWAY'''
                '[1]': '''SERVICE_UNAVAILABLE'''
              series: 
                '[0]': '''CLIENT_ERROR'''
              methods: 
                '[0]': '''GET'''
                '[1]': '''POST'''
                '[2]': '''PUT'''
                '[3]': '''DELETE'''
              backoff: 
                firstBackoff: '''100ms'''
                maxBackoff: '''500ms'''
                factor: 2
                basedOnPreviousValue: false
      'default-filters[0]': 
        name: RequestRateLimiter
        args: 
          key-resolver: '#{@apiKeyResolver}'
          redis-rate-limiter: 
            replenishRate: 500
            burstCapacity: 800
            requestedTokens: 1
      httpclient: 
        connect-timeout: 500
ribbon: 
  OkToRetryOnAllOperations: true
  MaxAutoRetries: 0
  MaxAutoRetriesNextServer: 3
michaelwangwangwang commented 1 year ago

Can someone answer me?

michaelwangwangwang commented 1 year ago

@spencergibb

ffrankozz commented 10 months ago

@michaelwangwangwang Have you found any solution to your problem. I am having a similar problem with later versions of the Spring boot on windows 10/11 machines.

spencergibb commented 6 months ago

version 3.x is no longer supported. Is this still an issue in 4.1.x?

Also in your yaml replace

'[0]': '''java.net.ConnectException'''

with

- java.net.ConnectException
spring-cloud-issues commented 5 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 5 months ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.