Home > Back-end >  Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to host.docker.inte
Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to host.docker.inte

Time:11-21

I have my app (REST Service) connecting to Keycloak for Auth purposes, and both of them are started using the same docker compose file (default Network). Keycloak and App come up and work absolutely fine when API is invoked.

When the application is left unused for some time and again same API is invoked I get the below error.

iam       | {"timestamp":"2022-11-18T12:25:47.055 0000","message":"fail to generate token","logger_name":"com.xxxxx.xxx.xxxxxxxxxxx.AuthController","thread_name":"http-nio-8081-exec-9","level":"ERROR","level_value":40000,"stack_trace":"javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to host.docker.internal:8085 [host.docker.internal/192.168.65.2] failed: Operation timed out (Connection timed out)\n\tat org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:341)\n\tat org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:464)\n\tat org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:152)\n\tat org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:115)\n\tat org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)\n\tat 

However, after timeout happens... successive invoke of API Works.

Not sure why do I get above error if Application is left idle (May be Token Expired but that should not result is Connection Timeout)

CodePudding user response:

Well, I Could not figure out the root cause but doing following changes has solved the problem.

  1. Adding network element as below and
  2. Assigning IP to each service
  3. Pointing to the correct IP of Keycloak in my App Service Definition.
keycloak:
  image: xxxx
  container_name: keycloak
  networks:
    my-network:
      ipv4_address: 172.29.1.2  
  ports:
    - 8085:8080
app:
  image: xxxx
  container_name: app
  environment:
    KEYCLOAK_HOST: http://172.29.1.2:8080
  networks:
    my-network:
      ipv4_address: 172.29.1.3
  ports:
    - 8081:8081
networks:   
  my-network:
    ipam:
      driver: default
      config:
        - subnet: 172.29.0.0/16
  • Related