java - OkHttp client timeout does not work when using NLB (Network Load Balancer) - Stack Overflow

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

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744939650a4602243.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信