We are using Netflix feign to connect to a downstream client, but our request.options connect and read timeouts are not working.
This is how we are passing parameters to the builder
Feign.builder()
.client(new OkHttpClient(okHttpClient))
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.options(new Request.Options(connectTimeoutInMS, readTimeoutInMs)
.target(*,*);
We have set readTimeout and ConnectionTimeout to 1 sec. But what we see is even when the target takes more than 1 sec to respond, it does not timeout and keeps trying to connect.
Your request options configurations are not working because you're defining an OkHttpClient, according to Feign's documentation:
OkHttpClient directs Feign's http requests to OkHttp, which enables SPDY and better network control.
So, if your OkHttpClient doesn't have defined these values, it will take defaults values, this value is 10000ms (you can find these values at line 373 here: https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/OkHttpClient.java). So, you should configure your OkHttpClient like:
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setConnectTimeout(timeout, TimeUnit.MILLISECONDS);
okHttpClient.setReadTimeout(timeout, TimeUnit.MILLISECONDS);
okHttpClient.setWriteTimeout(timeout, TimeUnit.MILLISECONDS);
来源:https://stackoverflow.com/questions/35571015/feign-builder-timeouts-not-working