consul-client icon indicating copy to clipboard operation
consul-client copied to clipboard

consul health client timeout

Open EvertMDC opened this issue 9 years ago • 8 comments

Hello,

I have an application that uses consul-client that is running fine on docker 1.11.2. When deploying the same container to a docker with version 1.12 I get the message that it cannot connect tot the ipv6 address of localhost, which is normal because consul is running on ipv4 localhost.

com.orbitz.consul.ConsulException: Consul request failed
    at com.orbitz.consul.util.Http.extractConsulResponse(Http.java:49)
    at com.orbitz.consul.HealthClient.getChecksByState(HealthClient.java:241)
    at com.orbitz.consul.HealthClient.getChecksByState(HealthClient.java:225)
    at test.consul.ConsulBasedApplicationManager$Updater.run(ConsulBasedApplicationManager.java:85)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:8500
    at com.orbitz.okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:142)
    at com.orbitz.okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
    at com.orbitz.okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188)
    at com.orbitz.okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
    at com.orbitz.okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
    at com.orbitz.okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
    at com.orbitz.okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
    at com.orbitz.okhttp3.RealCall.getResponse(RealCall.java:240)
    at com.orbitz.okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
    at com.orbitz.okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
    at com.orbitz.okhttp3.RealCall.execute(RealCall.java:57)
    at com.orbitz.retrofit.OkHttpCall.execute(OkHttpCall.java:174)
    at com.orbitz.consul.util.Http.extractConsulResponse(Http.java:47)
    ... 4 more

When changing consul = Consul.builder().build(); to consul = Consul.builder().withUrl("http://127.0.0.1:8500").build(); one would assume it would take the correct address. Unfortunately this gives a timeout.

com.orbitz.consul.ConsulException: Consul request failed
    at com.orbitz.consul.util.Http.extractConsulResponse(Http.java:49)
    at com.orbitz.consul.HealthClient.getChecksByState(HealthClient.java:241)
    at com.orbitz.consul.HealthClient.getChecksByState(HealthClient.java:225)
    at test.consul.ConsulBasedApplicationManager$Updater.run(ConsulBasedApplicationManager.java:85)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: timeout
    at com.orbitz.okio.Okio$3.newTimeoutException(Okio.java:207)
    at com.orbitz.okio.AsyncTimeout.exit(AsyncTimeout.java:261)
    at com.orbitz.okio.AsyncTimeout$2.read(AsyncTimeout.java:215)
    at com.orbitz.okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
    at com.orbitz.okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
    at com.orbitz.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
    at com.orbitz.okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:184)
    at com.orbitz.okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125)
    at com.orbitz.okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:723)
    at com.orbitz.okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81)
    at com.orbitz.okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:708)
    at com.orbitz.okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
    at com.orbitz.okhttp3.RealCall.getResponse(RealCall.java:241)
    at com.orbitz.okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
    at com.orbitz.okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
    at com.orbitz.okhttp3.RealCall.execute(RealCall.java:57)
    at com.orbitz.retrofit.OkHttpCall.execute(OkHttpCall.java:174)
    at com.orbitz.consul.util.Http.extractConsulResponse(Http.java:47)
    ... 4 more
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:203)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at com.orbitz.okio.Okio$2.read(Okio.java:139)
    at com.orbitz.okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
    ... 19 more

Is this an issue with the way the client connects to consul? Why is it trying to connect to ipv6?

EvertMDC avatar Oct 26 '16 12:10 EvertMDC

Are you running your app container with --net=host? Otherwise localhost isn't going to work.

rickfast avatar Oct 29 '16 15:10 rickfast

There is a consul agent running inside the container so once the container starts up it registers its service. A curl inside the container to localhost works.

EvertMDC avatar Nov 02 '16 11:11 EvertMDC

Not sure what's going on here. I can't reproduce this. I'll look at the OK HTTP docs, but the Consuk code itself doesn't use IPv6

rickfast avatar Nov 03 '16 12:11 rickfast

Can I help you with some additional information maybe?

EvertMDC avatar Nov 15 '16 14:11 EvertMDC

if you have more information to give, please do.

rickfast avatar Nov 18 '16 20:11 rickfast

Was this ever resolved? I'm having the same problem, would like to know if there's a workaround.

curena avatar Apr 26 '17 01:04 curena

Unfortunately not. This is the oldest item on my todo list but I'm not really sure where I could find more info.

EvertMDC avatar Apr 26 '17 08:04 EvertMDC

I am also running into this same issue with a dockerized consul agent running on the same host.

edit: I figured out this issue and it had nothing to do with the library. I have the orbitz client running within my dockerized container. Everything is working as expected 👍

khaosans avatar May 18 '17 21:05 khaosans