You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/10/11 07:19:13 UTC

[GitHub] [servicecomb-java-chassis] five111 commented on issue #2603: [Pinned Problem]connection was closed

five111 commented on issue #2603:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2603#issuecomment-939756062


   ### 针对这个问题,在vertx未升级的版本其实存在一个废弃连接的使用导致此问题发生。
   ### 这里提供一个比较容易触发的场景:
   
   - 使用servicecomb  vertx升级之前的版本,我这里使用的2.1.5版本,同时通信模式都是使用的 servlet 
   - 客户端开启一个定时任务,比如每隔{time}s发送一个请求到服务端, 这个{time}与服务端tomcat设置的断开连接时间要一直或相近比较容易触发
   
   ### 我们通过抓包,发现了导致此问题的原因: 
   客户端复用连接池,在TCP连接四次挥手期间发送请求,会导致请求失败  
   
   ![huishou](https://user-images.githubusercontent.com/19482564/136747129-ca1915e7-bab7-4605-8310-b3f028394778.png)
   
   
   ### 解决办法
   
   1. 请求量少的可以用短连接
   2. 我们请求量较大,通过重试机制去解决此问题
   
   
   ### 复现demo
   ### 客户端:
   ``` 
      // 起5个线程发请求  线程数根据maxpoolsize和核心数配置
       public void run(ApplicationArguments args) throws Exception {
           for (int i = 0; i < 5; i++) {
               new Thread(new SendThread()).start();
           }
       }
     //发送请求
     public void testSsl() throws InterruptedException {
           RestTemplate restTemplate = RestTemplateBuilder.create();
           SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:SSS");
           for(int i = 0; i< 10; i++){
               if(i == 0 ){
                   Thread.sleep(20000);
               }
               String url = "cse://test-provider2/provider/tomcat/hello/";
               // 间隔时间和服务端tomcat的连接保持时间相关
               Thread.sleep(2000 + new Random().nextInt(3) + 1);
               UUID uuid = UUID.randomUUID();
               System.out.println(formatter.format(new Date())+uuid);
               ResponseEntity<String> responseEntity =
                       restTemplate.getForEntity(url + uuid, String.class);
               System.out.println("get result "+formatter.format(new Date()) + " " + responseEntity.getBody());
   
           }
       }
   ```
   ### 服务端:
   ```
   // 接口
   @GetMapping("/hello/{name}")
       public String sayHello(@PathVariable("name") @Length String name, InvocationContext invocationContext) throws InterruptedException {
           return name+", hello";
       }
   // tomcat配置
   server:
     port: 8888
     tomcat:
       accesslog:
         directory: D:\code\CSE\demo-2
         enabled: true
         pattern: '%t %a %A %m %U%q %s %D %I %B'
       max-connections: 1000
       accept-count: 200
       threads:
         max: 200
       connection-timeout: 2000
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org