彻底解决connect reset
connect reset问题
服务器发生connect reset原因不详说了,没有见过的可以看下connect reset原因
这个博客讲述的很正确,稍微补充下,有时改成短链接不一定能完全解决该问题,因为在http请求发送和返回响应肯定是需要时间的,在服务器高并发环境下很容易触发安全策略或者其他策略导致链接强制断开,因此需要在转化成短链接的同时增加重试才能根本解决问题。
这里使用okhttp4使用拦截器重试,这样能大概率解决所有问题
private static OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(0, TimeUnit.SECONDS).readTimeout(0, TimeUnit.SECONDS).retryOnConnectionFailure(true).addInterceptor(myOkHttpRetryInterceptor).build();
其中myOkHttpRetryInterceptor可以仿照这个博客编写
package com.gomefinance.esign.httpretry;import lombok.extern.slf4j.Slf4j;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.List;/*** User: Administrator* Date: 2017/9/19* Description:*/@Slf4j
public class MyOkHttpRetryInterceptor implements Interceptor {public int executionCount;//最大重试次数private long retryInterval;//重试的间隔MyOkHttpRetryInterceptor(Builder builder) {this.executionCount = builder.executionCount;this.retryInterval = builder.retryInterval;}@Overridepublic Response intercept(Chain chain) throws IOException {Request request = chain.request();Response response = doRequest(chain, request);int retryNum = 0;while ((response == null || !response.isSuccessful()) && retryNum <= executionCount) {log.info("intercept Request is not successful - {}",retryNum);final long nextInterval = getRetryInterval();try {log.info("Wait for {}",nextInterval);Thread.sleep(nextInterval);} catch (final InterruptedException e) {Thread.currentThread().interrupt();throw new InterruptedIOException();}retryNum++;// retry the requestresponse = doRequest(chain, request);}return response;}private Response doRequest(Chain chain, Request request) {Response response = null;try {response = chain.proceed(request);} catch (Exception e) {}return response;}/*** retry间隔时间*/public long getRetryInterval() {return this.retryInterval;}public static final class Builder {private int executionCount;private long retryInterval;public Builder() {executionCount = 3;retryInterval = 1000;}public MyOkHttpRetryInterceptor.Builder executionCount(int executionCount){this.executionCount =executionCount;return this;}public MyOkHttpRetryInterceptor.Builder retryInterval(long retryInterval){this.retryInterval =retryInterval;return this;}public MyOkHttpRetryInterceptor build() {return new MyOkHttpRetryInterceptor(this);}}}
彻底解决connect reset相关推荐
- 如何解决Connect超时导致的阻塞问题
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/clirus/article/detai ...
- vmware中的Ubuntu安装ssh全家桶(解决connect to host localhost port 22: Connection refused)...
2019独角兽企业重金招聘Python工程师标准>>> 网上查询过异常信息后得知系统需要安装ssh服务. 1.重现问题:ssh localhost 报错connect to host ...
- 解决 connect to host github.com port 22 operation timed out
本来好好地.不知道为什么不能push了.估计是被墙,于是搜搜解决办法.改换端口 参考 https://mozillazg.com/2015/08/use-443-port-fix-github-con ...
- TCP解决connect函数的超时问题
在一个TCP套接口被设置为非阻塞之后调用connect,connect会立即返回EINPROGRESS错误,表示连接操作正在进行中,但是仍未完成;同时TCP的三路握手操作继续进行;在这之后,我们可以调 ...
- nginx报错解决connect() to unix:/tmp/php-cgi-73.sock failed (111: Connection refused
2020/06/09 08:50:16 [error] 6608#0: *1 connect() to unix:/tmp/php-cgi-73.sock failed (111: Connectio ...
- 解决connect阻塞
步骤1: 设置非阻塞,启动连接 实现非阻塞 connect ,首先把 sockfd 设置成非阻塞的.这样调用 connect 可以立刻返回,根据返回值和 errno 处理三种情况: (1) 如果返回 ...
- 在QT中使用socket编程:解决connect函数名称冲突
问题 当使用QT做可视化界面的时候,我们知道connect函数是连接函数,用于连接信号与槽,但connect在C/C++的socket网络编程中也是一个必不可少的函数,作用是发送连接请求,建立tcp连 ...
- 解决git reset后push冲突
/*1.新建分支*/ git checkout -b temp //新建分支并切换到temp分支 git push origin temp:temp //将代码push到temp分支 /*2.删除主分 ...
- 最近纠结致死的一个java报错java.net.SocketException: Connection reset 终于得到解决
自从SEOTcs系统11月份24日更新了一下SEO得分算法以来,一直困扰我的一个问题出现了,java的数据job任务,在执行过程中会经常报以下的错误: "2011-12-03 18:00:3 ...
最新文章
- 10.2.2 选择器
- ES6 Fetch API和Cookie相关的知识点
- 事件冒泡 bubbles cancelBubble stopPropagation() stopImmediatePropagation() 区别
- C++ cin 实现循环读入
- 20个最佳WordPress SEO插件
- STM32中断与事件
- GNS3+GNS3 VM
- Win10PE网络版.iso UEFI、BIOS双启动
- Graphpad prism8
- 西门子uss通讯实例_西门子USS通信调试经历
- DELL PERC 系列阵列卡详解
- Pano2VR 6 for Mac中文破解版永久激活方法附授权密钥
- S3C2440裸机开发----点亮LED
- Android 查看 wifi 密码
- 判断table中的tbody是否有数据
- 生成的exe程序默认以管理员权限启动
- 多少秒算长镜头_电影术语中长镜头是什么意思?
- 论文阅读:SCENE TRANSFORMER: A UNIFIED ARCHITECTUREFOR PREDICTING MULTIPLE AGENT TRAJECTORIES
- [Idea] Add Abbreviation的使用
- epub文件是什么文件?如何用安卓手机打开?