This repository was archived by the owner on Nov 29, 2018. It is now read-only.
-
-
Couldn't load subscription status.
- Fork 195
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
Invalid use of SingleClientConnManager - exception #2526
Copy link
Copy link
Closed
Description
Originally reported on Google Code with ID 2526
Hi,
if RemoteWebDriver is used, the 'java.lang.IllegalStateException: Invalid use of SingleClientConnManager:
connection still allocated.' exception can be raised when a method from RemoteWebDriver
is called and it is interrupted (due to SIGTERM, CTRL+C, etc.) or it is executed in
parallel. There are several opened issues for this topic.
This problem becomes more complex when the server is in a grid, due to the browser
remains opened, and, sometimes, the server becomes unstable (or slow).
I have worked on this issue, and I guess I found a solution.
At 'HttpCommandExecutor' I have added this method (this code is attached):
<code>
public void cleanClientConnection() {
// Shutdown current connection and open another one
client.getConnectionManager().shutdown();
HttpParams params = new BasicHttpParams();
// Use the JRE default for the socket linger timeout.
params.setParameter(CoreConnectionPNames.SO_LINGER, -1);
HttpClientParams.setRedirecting(params, false);
client = new DefaultHttpClient(getClientConnectionManager(params),
params);
if (remoteServer.getUserInfo() != null) {
// Use HTTP Basic auth
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
remoteServer.getUserInfo());
((DefaultHttpClient) client).getCredentialsProvider()
.setCredentials(AuthScope.ANY, credentials);
}
// Some machines claim "localhost.localdomain" is the same as
// "localhost".
// This assumption is not always true.
String host = remoteServer.getHost().replace(".localdomain", "");
targetHost = new HttpHost(host, remoteServer.getPort(),
remoteServer.getProtocol());
}
</code>
And, at 'RemoteWebDriver.quit' method, before perform any action, previous method 'cleanClientConnection'
is called.
Summarizing, this method closes any opened connections and creates another client.
Reported by mpuchol@netquest.com on 2011-09-22 13:27:20
- _Attachment: [NQHttpCommandExecutor.java](https://storage.googleapis.com/google-code-attachments/selenium/issue-2526/comment-0/NQHttpCommandExecutor.java)_