I have a Java application built with Spring Boot which uses Selenium webdriver in order to get some pieces of information from a website and then save the data into the database. The webdriver version is 79.0.3945.36 and the chrome version is 79.0.3945.79. This problem (Failed to connect to localhost/0:0:0:0:0:0:0:1:15239) does not appear on every run of the application, it occurs from time to time.
At first the application does some synchronous methods on the database and then, it opens two threads which run asynchronous in order to get data with Selenium and add the data into the database. After the first thread finishes, the application fails ( the second thread is still in progress at that moment ).
At the end of the application, there is a part when the chrome and chromedriver processes are killed in order to avoid gathering too many processes ( this appears at the end of the class posted). I will add some pieces of code:
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/tennis</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">2</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
The class with the method that fails ( the line is not shown in the stacktrace):
@Async
public void processDatabaseMatchesSecond() throws InterruptedException, IOException {
Driver driver2 = new Driver();
WebDriver webDriver2 = driver2.createDriver();
//System.out.println("second method");
HashMap<String, Float> playerStatsFirstPlayer = new HashMap<>();
HashMap<String, Float> playerStatsSecondPlayer = new HashMap<>();
HashMap<String, Float> custom_stats_player1 = new HashMap<>();
HashMap<String, Float> custom_stats_player2 = new HashMap<>();
boolean h2h_checker = false;
List<MatchesEntity> matchesEntities = matchesRepository.getMatchesWithNoPickScore();
int size = matchesEntities.size();
for (int i = size / 2; i < size; i++) {
MatchesEntity currentMatchesEntity = matchesEntities.get(i);
if (currentMatchesEntity.getPickScore() == 0) {
try {
playerStatsFirstPlayer.putAll(player_profile.player_stats(playersRepository.selectIdByFullName(currentMatchesEntity.getNamePlayer1()), currentMatchesEntity.getNamePlayer1(), webDriver2));
if (playerStatsFirstPlayer.isEmpty()) {
matchesRepository.delete(currentMatchesEntity);
logger.error(currentMatchesEntity.getNamePlayer1() + " no profile");
continue;
}
currentMatchesEntity = latest_matches.get_latest_matches(currentMatchesEntity.getId(), currentMatchesEntity.getNamePlayer1(), webDriver2);
} catch (Exception e) {
webDriver2.quit();
webDriver2 = null;
webDriver2 = driver2.createDriver();
webDriver2.manage().deleteAllCookies();
playerStatsFirstPlayer.putAll(player_profile.player_stats(playersRepository.selectIdByFullName(currentMatchesEntity.getNamePlayer1()), currentMatchesEntity.getNamePlayer1(), webDriver2));
currentMatchesEntity = latest_matches.get_latest_matches(currentMatchesEntity.getId(), currentMatchesEntity.getNamePlayer1(), webDriver2);
}
}
}
thread2_finished = 1;
webDriver2.close();
if (thread1_finished == 1 && thread2_finished == 1) {
if (System.getProperty("os.name").contains("Windows")) {
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe /T");
Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe /T");
}
}
logger.info("Thread 2: SUCCES");
}
Stacktrace:
2019-12-17 17:41:48.949 ERROR 3092 --- [ task-10] .a.i.SimpleAsyncUncaughtExceptionHandler : Unexpected exception occurred invoking async method: public void processing.PlayersProcessor.processDatabaseMatchesSecond() throws java.lang.InterruptedException,java.io.IOException
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:15239
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'VPS15803', ip: '2.56.214.35', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92) ~[selenium-remote-driver-3.14.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) ~[selenium-remote-driver-3.14.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605) ~[selenium-remote-driver-3.14.0.jar:na]
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:448) ~[selenium-remote-driver-3.14.0.jar:na]
at processing.PlayersProcessor.processDatabaseMatchesSecond(PlayersProcessor.java:244) ~[classes/:0.0.1-SNAPSHOT]
at processing.PlayersProcessor$$FastClassBySpringCGLIB$$ff2e149b.invoke(<generated>) ~[classes/:0.0.1-SNAPSHOT]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_231]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_231]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_231]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_231]
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:15239
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) ~[okhttp-3.11.0.jar:na]
at okhttp3.RealCall.execute(RealCall.java:77) ~[okhttp-3.11.0.jar:na]
at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:105) ~[selenium-remote-driver-3.14.0.jar:na]
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:155) ~[selenium-remote-driver-3.14.0.jar:na]
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) ~[selenium-remote-driver-3.14.0.jar:na]
... 13 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_231]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_231]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_231]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_231]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_231]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_231]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_231]
at java.net.Socket.connect(Socket.java:606) ~[na:1.8.0_231]
at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129) ~[okhttp-3.11.0.jar:na]
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245) ~[okhttp-3.11.0.jar:na]
... 33 common frames omitted