bobcarroll / jira-client

A simple JIRA REST client for Java
Other
474 stars 379 forks source link

Does anyone get this exception? -- Caused by: java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. #110

Open Alan-Chen-au opened 9 years ago

Alan-Chen-au commented 9 years ago

I checked this version two months ago. I use jira-client in Multi-thread env.

any suggestion? Thanks Alan

Alan-Chen-au commented 9 years ago

more information shown below :

net.rcarz.jiraclient.JiraException: Failed to retrieve issue PROVSERV-14990 at net.rcarz.jiraclient.Issue.realGet(Issue.java:1001) at net.rcarz.jiraclient.Issue.get(Issue.java:1024) at net.rcarz.jiraclient.JiraClient.getIssue(JiraClient.java:99) at net.onthenet.jirarest.javaclient.OTNIssue.(OTNIssue.java:76) at net.onthenet.dslprovisioning.eo.DslCustomerOrder$JiraDslCancelHandlerThread.run(DslCustomerOrder.java:1162) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one. at org.apache.http.util.Asserts.check(Asserts.java:34) at org.apache.http.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:160) at org.apache.http.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:142) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:422) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at net.rcarz.jiraclient.RestClient.request(RestClient.java:129) at net.rcarz.jiraclient.RestClient.get(RestClient.java:273) at net.rcarz.jiraclient.Issue.realGet(Issue.java:999)

Alan-Chen-au commented 8 years ago

solved and updated JiraClient.java

... ... import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; ... ...

public class JiraClient {

private RestClient restclient = null;
private String username = null;
// Added by Alan Chen for Multi-thread problem
// Date : 2015/11/09
private static CloseableHttpClient httpClient = null;
private static PoolingHttpClientConnectionManager connManager = null;

/**
 * Creates a JIRA client.
 *
 * @param uri Base URI of the JIRA server
 * @throws JiraException 
 */
public JiraClient(String uri) throws JiraException {
    this(uri, null);
}

/**
 * Creates an authenticated JIRA client.
 *
 * @param uri Base URI of the JIRA server
 * @param creds Credentials to authenticate with
 * @throws JiraException 
 */
public JiraClient(String uri, ICredentials creds) throws JiraException {
    // Modified by Alan Chen for Muti-thread problem
    // Date : 2015/11/09
    // DefaultHttpClient httpclient = new DefaultHttpClient();
    if (null == httpClient) {
      connManager = new PoolingHttpClientConnectionManager();
      connManager.setDefaultMaxPerRoute(20);
      connManager.setMaxTotal(40);
      httpClient = HttpClients.custom().setConnectionManager(connManager).build();
    }

    restclient = new RestClient(httpClient, creds, URI.create(uri));

    if (creds != null) {
        username = creds.getLogonName();
        //intialize connection if required
        creds.initialize(restclient);
    }
}
jefdcruz commented 8 years ago

I still get this error, happens when multiple requests are made simultaneously

Alan-Chen-au commented 8 years ago

send me your sample code and let me have a look !

On Wed, Jan 6, 2016 at 6:28 AM, jefdcruz notifications@github.com wrote:

I still get this error, happens when multiple requests are made simultaneously

— Reply to this email directly or view it on GitHub https://github.com/rcarz/jira-client/issues/110#issuecomment-169122534.

btiernay commented 8 years ago

What do you think about having a constructor that allows passing in the HttpClient?

tess1o commented 8 years ago

I'm also getting this issue. I use this library in a Spring boot application. I have a Service (scope = prototype) where the jira API is used. I'm getting the exception only when multiple requests are made simultaneously.

Update:

I see your fix on GitHub, however, I don't see it in net.rcarz:jira-client:0.5

I use the following dependency in Gradle:

// https://mvnrepository.com/artifact/net.rcarz/jira-client
compile group: 'net.rcarz', name: 'jira-client', version: '0.5'

Thank you.

Alan-Chen-au commented 8 years ago

@tess1o net.rcarz:jira-client:0.5 ---> this was previous release; which cannot support this feature. Just clone the current one which should be fine.

Alan-Chen-au commented 8 years ago

@btiernay It is another option. I believe it is a good way in some scenarios.
@rcarz may give us more comments I believe.