Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restful/HttpInvoker http连接泄露 #14

Open
dingjs opened this issue Dec 16, 2020 · 0 comments
Open

restful/HttpInvoker http连接泄露 #14

dingjs opened this issue Dec 16, 2020 · 0 comments

Comments

@dingjs
Copy link

dingjs commented Dec 16, 2020

        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的情况下,连接就没关闭,导致连接泄露。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant