admin管理员组

文章数量:1410674

I’m facing an issue where the OkHttp client timeout doesn't work as expected.

Conditions:

  • About the Program:

    • java client (Feign) generated using OpenAPI Generator.
    • Using OkHttp 3 client.
  • Flow:
    myapp-->nlb-->ingress-->API

    • When the NLB (Network Load Balancer) stops, the client responds immediately (in this case, the timeout is irrelevant).
    • If the NLB is functioning properly and ingress is stopped, for some reason, no response is returned. Additionally, the configured timeout does not work, and the client waits for more than one hour.

The issue: When NLB does not return a response, my app keeps waiting for a response, ignoring the timeout configuration.

Questions: What could be causing this behavior? How can I ensure that the timeout is respected when NLB fails to respond?

The timeout was shortened as shown below in the configuration, and retries were also disabled. However, this does not resolve the issue. The client continues to wait beyond the specified timeout period, and no timeout error occurs.
The code I am using is as follows:

Builder builder = apiClient.getFeignBuilder();
// Options options = new Options(10L, TimeUnit.SECONDS, 14L, TimeUnit.MINUTES, true);
// builder.options(options);
OkHttpClient client = new OkHttpClient.Builder()
     .callTimeout(10, TimeUnit.SECONDS)
     .connectTimeout(5, TimeUnit.SECONDS)
     .readTimeout(5, TimeUnit.SECONDS)
     .writeTimeout(5, TimeUnit.SECONDS)
     .retryOnConnectionFailure(false)
     .build();
Client client1 = new feign.okhttp.OkHttpClient(client);
builder.client(client1);
apiClient.setFeignBuilder(builder);

本文标签: javaOkHttp client timeout does not work when using NLB (Network Load Balancer)Stack Overflow