Search code examples
spring-bootherokuspring-cloudnetflix-eurekaspring-cloud-gateway

Error 500 on spring cloud gateway finishConnect(..) on Heroku


I use Eureka with spring boot£. 1 server, 1 gateway, and 2 api, in my localhost i have no problems but when i deploy it on Heroku i can't reach an api through the api gateway. The EUREKA server discover all my services with no issues.

In the log of the gateway i have an ERROR 500

2022-11-22T14:23:30.428847+00:00 app[web.1]: 2022-11-22 14:23:30.428  INFO 4 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-11-22T14:23:30.666161+00:00 app[web.1]: 2022-11-22 14:23:30.665  INFO 4 --- [           main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2022-11-22T14:23:31.365410+00:00 app[web.1]: 2022-11-22 14:23:31.365  WARN 4 --- [           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2022-11-22T14:23:31.391840+00:00 app[web.1]: 2022-11-22 14:23:31.391  INFO 4 --- [           main] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2022-11-22T14:23:31.467468+00:00 app[web.1]: 2022-11-22 14:23:31.465  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Initializing Eureka in region us-east-1
2022-11-22T14:23:31.473095+00:00 app[web.1]: 2022-11-22 14:23:31.472  INFO 4 --- [           main] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2022-11-22T14:23:31.498500+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2022-11-22T14:23:31.498507+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2022-11-22T14:23:31.498541+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2022-11-22T14:23:31.498575+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false
2022-11-22T14:23:31.498609+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2022-11-22T14:23:31.498651+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2022-11-22T14:23:31.498691+00:00 app[web.1]: 2022-11-22 14:23:31.498  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2022-11-22T14:23:32.651073+00:00 app[web.1]: 2022-11-22 14:23:32.650  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : The response status is 200
2022-11-22T14:23:32.657211+00:00 app[web.1]: 2022-11-22 14:23:32.656  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30
2022-11-22T14:23:32.661123+00:00 app[web.1]: 2022-11-22 14:23:32.660  INFO 4 --- [           main] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2022-11-22T14:23:32.668470+00:00 app[web.1]: 2022-11-22 14:23:32.668  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1669127012667 with initial instances count: 1
2022-11-22T14:23:32.670420+00:00 app[web.1]: 2022-11-22 14:23:32.670  INFO 4 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application API-GATEWAY with eureka with status UP
2022-11-22T14:23:32.671101+00:00 app[web.1]: 2022-11-22 14:23:32.670  INFO 4 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1669127012670, current=UP, previous=STARTING]
2022-11-22T14:23:32.673386+00:00 app[web.1]: 2022-11-22 14:23:32.673  INFO 4 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_API-GATEWAY/api-gateway:21401: registering service...
2022-11-22T14:23:32.751146+00:00 app[web.1]: 2022-11-22 14:23:32.750  INFO 4 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_API-GATEWAY/api-gateway:21401 - registration status: 204
2022-11-22T14:23:33.561901+00:00 heroku[web.1]: State changed from starting to up
2022-11-22T14:23:33.486111+00:00 app[web.1]: 2022-11-22 14:23:33.485  INFO 4 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 21401
2022-11-22T14:23:33.488877+00:00 app[web.1]: 2022-11-22 14:23:33.488  INFO 4 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 21401
2022-11-22T14:23:33.526112+00:00 app[web.1]: 2022-11-22 14:23:33.525  INFO 4 --- [           main] com.medhead.gateway.GatewayApplication   : Started GatewayApplication in 13.001 seconds (JVM running for 13.623)
2022-11-22T14:23:35.370016+00:00 heroku[router]: at=info method=GET path="/" host=headmed-gateway.herokuapp.com request_id=cd66391f-2d15-4701-b0f9-c60c5c3f4b89 fwd="92.158.60.103" dyno=web.1 connect=0ms service=146ms status=404 bytes=387 protocol=https
2022-11-22T14:24:32.698383+00:00 heroku[router]: at=info method=GET path="/" host=headmed-gateway.herokuapp.com request_id=e5da2cfa-990f-4cab-ac75-b8e63ba6960e fwd="92.158.60.103" dyno=web.1 connect=0ms service=11ms status=404 bytes=387 protocol=https
2022-11-22T14:24:48.125828+00:00 heroku[router]: at=info method=GET path="/actuator/health" host=headmed-gateway.herokuapp.com request_id=84a74ade-2e24-4b00-a2ba-e87e23979557 fwd="92.158.60.103" dyno=web.1 connect=0ms service=51ms status=200 bytes=133 protocol=https
2022-11-22T14:25:37.041666+00:00 heroku[router]: at=info method=GET path="/patient-service/patients" host=headmed-gateway.herokuapp.com request_id=41c71d85-f335-494c-9b2d-119ee858a606 fwd="92.158.60.103" dyno=web.1 connect=0ms service=223ms status=500 bytes=411 protocol=https
2022-11-22T14:25:37.038507+00:00 app[web.1]: 2022-11-22 14:25:37.037 ERROR 4 --- [or-http-epoll-8] a.w.r.e.AbstractErrorWebExceptionHandler : [1a0ff15a-4]  500 Server Error for HTTP GET "/patient-service/patients"
2022-11-22T14:25:37.038521+00:00 app[web.1]: 
2022-11-22T14:25:37.038522+00:00 app[web.1]: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:6115
2022-11-22T14:25:37.038523+00:00 app[web.1]:    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
2022-11-22T14:25:37.038525+00:00 app[web.1]: Error has been observed at the following site(s):
2022-11-22T14:25:37.038527+00:00 app[web.1]:    *__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
2022-11-22T14:25:37.038528+00:00 app[web.1]:    *__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
2022-11-22T14:25:37.038529+00:00 app[web.1]:    *__checkpoint ⇢ HTTP GET "/patient-service/patients" [ExceptionHandlingWebHandler]
2022-11-22T14:25:37.038530+00:00 app[web.1]: Original Stack Trace:
2022-11-22T14:25:37.038530+00:00 app[web.1]: Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
2022-11-22T14:25:37.038531+00:00 app[web.1]:    at io.netty.channel.unix.Errors.newConnectException0(Errors.java:155) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038531+00:00 app[web.1]:    at io.netty.channel.unix.Errors.handleConnectErrno(Errors.java:128) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038531+00:00 app[web.1]:    at io.netty.channel.unix.Socket.finishConnect(Socket.java:359) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038533+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:710) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038533+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:687) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038534+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:567) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038535+00:00 app[web.1]:    at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:489) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038535+00:00 app[web.1]:    at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038535+00:00 app[web.1]:    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038536+00:00 app[web.1]:    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038536+00:00 app[web.1]:    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.038536+00:00 app[web.1]:    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2022-11-22T14:25:37.038537+00:00 app[web.1]: 
2022-11-22T14:25:37.092716+00:00 app[web.1]: 2022-11-22 14:25:37.091 ERROR 4 --- [or-http-epoll-1] a.w.r.e.AbstractErrorWebExceptionHandler : [0a942c39-5]  500 Server Error for HTTP GET "/patient-service/patients"
2022-11-22T14:25:37.092717+00:00 app[web.1]: 
2022-11-22T14:25:37.092718+00:00 app[web.1]: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:6115
2022-11-22T14:25:37.092719+00:00 app[web.1]:    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
2022-11-22T14:25:37.092720+00:00 app[web.1]: Error has been observed at the following site(s):
2022-11-22T14:25:37.092720+00:00 app[web.1]:    *__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
2022-11-22T14:25:37.092721+00:00 app[web.1]:    *__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
2022-11-22T14:25:37.092722+00:00 app[web.1]:    *__checkpoint ⇢ HTTP GET "/patient-service/patients" [ExceptionHandlingWebHandler]
2022-11-22T14:25:37.092722+00:00 app[web.1]: Original Stack Trace:
2022-11-22T14:25:37.092722+00:00 app[web.1]: Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
2022-11-22T14:25:37.092723+00:00 app[web.1]:    at io.netty.channel.unix.Errors.newConnectException0(Errors.java:155) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092723+00:00 app[web.1]:    at io.netty.channel.unix.Errors.handleConnectErrno(Errors.java:128) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092724+00:00 app[web.1]:    at io.netty.channel.unix.Socket.finishConnect(Socket.java:359) ~[netty-transport-native-unix-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092725+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:710) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092725+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:687) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092725+00:00 app[web.1]:    at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:567) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092726+00:00 app[web.1]:    at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:489) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092726+00:00 app[web.1]:    at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092726+00:00 app[web.1]:    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092727+00:00 app[web.1]:    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092727+00:00 app[web.1]:    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.84.Final.jar!/:4.1.84.Final]
2022-11-22T14:25:37.092727+00:00 app[web.1]:    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2022-11-22T14:25:37.092728+00:00 app[web.1]: 
2022-11-22T14:25:37.095360+00:00 heroku[router]: at=info method=GET path="/patient-service/patients" host=headmed-gateway.herokuapp.com request_id=6657476d-7856-4a93-8243-5f5fb56b2921 fwd="92.158.60.103" dyno=web.1 connect=0ms service=14ms status=500 bytes=411 protocol=https

this is my application prop for my and micro service

application-heroku.yml (EUREKA SERVER)

server:
  port: ${PORT:8761}
spring:
  application:
    name: eureka-server
  cloud:
    service-registry:
      auto-registration:
        enabled: false
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
management:
  endpoints:
    web:
      exposure:
        include: "*"

application-heroku.yml (GATEWAY)

server:
  port: ${PORT:8082}
  forward-headers-strategy: framework
spring:
  application:
    name: api-gateway
  cloud:
    discovery:
      enabled: true
    gateway:
      globalcors:
        add-to-simple-url-handler-mapping: true
      metrics:
        enabled: true
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
      routes:
        - id: patient-service
          uri: lb://patient-service
          predicates:
            - Path=/patients/**
          filters:
            - RewritePath=/patients(?<segment>/?.*), $\{segment}
eureka:
  client:
    service-url:
      defaultZone: https://headmed-eureka.herokuapp.com/eureka/
  instance:
    hostname: localhost
    nonSecurePort: 80

application-heroku.yml (MICROSERVICE)

server:
  port: ${PORT:8080}
  forward-headers-strategy: none
eureka:
  client:
    enabled: true
    service-url:
      defaultZone:  https://headmed-eureka.herokuapp.com/eureka/
  instance:
    hostname: localhost
    instance-id: ${spring.application.name}:${random.uuid}
spring:
  application:
    name: patient-service
  datasource:
    url: jdbc:h2:mem:patient;
    username: sa
    password: password
    driverClassName: org.h2.Driver
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    show-sql: true
    defer-datasource-initialization: true
    hibernate:
      ddl-auto: create-drop
    generate-ddl: true
    database: h2
  sql:
    init:
      mode: always
  h2:
    console:
      enabled: true
      path: /h2
  data:
    jpa:
      repositories:
        bootstrap-mode: default
springdoc:
  swagger-ui:
    path: /swagger-ui

I think the issue is located on Heroku but i have no idea for a workaround.

I checked to using the nonSecurePort but it's not working.


Solution

  • I solved the problem by adding.

    non-secure-port-enabled: true
    secure-port-enabled: false
    non-secure-port: 80
    secure-port: 443