dubboclub / dubbo-plus

dubbo的插件集合
Apache License 2.0
319 stars 180 forks source link

restful/HttpInvoker http连接泄露 #14

Open dingjs opened 3 years ago

dingjs commented 3 years ago
        CloseableHttpResponse response =  httpclient.execute(httpPost);
        int responseCode = response.getStatusLine().getStatusCode();
        if(responseCode==200){
            HttpEntity responseEntity = response.getEntity();
            if(responseEntity!=null){
                return EntityUtils.toByteArray(responseEntity);
            }
        }else if(responseCode==404){
            throw new RpcException(RpcException.UNKNOWN_EXCEPTION,"not found service for url ["+url+"]");
        }else if(responseCode==500){
            throw new RpcException(RpcException.NETWORK_EXCEPTION,"occur an exception at server end.");
        }

CloseableHttpResponse需要在finally中关闭,不然responseCode在不等于200的情况下,连接就没关闭,导致连接泄露。