I have a webapp that is running on amazon ec2 on tomcat with hibernate and rest, my mySQL is standalone instance through amazon rds.
Once i start my webapp - everything is working fine, but recently i configured daily backups on my database and then started seeing problems with my webapp connecting to mySQL.
Basically the problem is only happens if my webapp was started before i mysql instance was restarted(backed up). Then after mySQL restart for some reason any connections to it from my webapp are failing.
It all resolves once i restart my ec2 vm (It might resolve if i restart tomcat as well, but i haven't tried that)
How can i make sure my webapp gets connected back to the mysql after mysql restart?
This is what im getting written to my log:
21-May-2015 11:42:27.857 WARN [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 0, SQLState: 08S01
21-May-2015 11:42:27.857 ERROR [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions Communications link failure
The last packet successfully received from the server was 200,187 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
Any suggestions on what to dig into?
You should use a connection pool. For Hibernate, you can use c3p0.
In your hibernate properties set the following
hibernate.connection.provider_class = org.hibernate.connection.C3P0ConnectionProvider
Then, in a c3p0.properties file, put these properties to retry to reconnect indefinitely every 3 seconds when database is down:
c3p0.acquireRetryAttempts = 0
c3p0.acquireRetryDelay = 3000
c3p0.breakAfterAcquireFailure = false
See this section for more details on how to recover from a database outage.
Related
I am building an app using Spring Boot with MSSQL. For connection pooling I am using Tomcat JDBC.
My question what happens to the connection pool when a database is taken offline for a few minutes and what is the best way to recover from this database going offline.
I have tried the following tomcat connection pool configuration and when the database was taken offline and then brought online new connections were not established. I keep gettin the exception com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Tomcat JDBC Configuration:
primary.datasource.tomcat.testWhileIdle=true
primary.datasource.validationQuery=SELECT 1
primary.datasource.validationInterval=34000
primary.datasource.initial-size=10
primary.datasource.max-active=50
primary.datasource.max-idle=20
primary.datasource.min-idle=10
primary.datasource.timeBetweenEvictionRunsMillis=34000
primary.datasource.minEvictableIdleTimeMillis=55000
primary.datasource.removeAbandoned=true
primary.datasource.removeAbandonedTimeout=55000
Please note that I have two datasources configured
I have a JSP web application deployed on a Weblogic server connected to an Oracle Database. There is no datasource set in the weblogic server instance and the application communicates with the database on it's own (with jdbc). However, every morning when I try to access the web page I get a 'No more data to read from socket' error. I reset the weblogic server and everything gets back to normal, but the thing is I can't keep restarting the server every morning.
Is there anyway that this can be fixed automatically? I think it has something to do with the connections in the pool, probably being disabled by oracle but still considered active by the application...
Thanks
I did manage to get this corrected.
What I did was creating a datasource in the Weblogic admin console and then configure my app to use this datasource. It was still giving the error initially but then I unchecked the "Keep Connection After Local Transaction" box from the datasource transaction options and this fixed the problem.
Hi I have inherited a a Websphere 6.1 Community Edition that hosts several applications. They all use the same pooled DB connections to MySql. Yesterday the connection pool would run out after about 2 hours requiring a server restart... ever 2 hours.... not great. So tonight I have all the modules stopped and am going to add them one by one to see which one is the culprit. However, this leads me to the problem in the subject, when the websphere server boots it give me this every 15 minutes:
ERROR [RecoveryController] Recovery error: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_recover'.
As far as I know there is no SQL server used in any of the clients apps. Is this something that comes with WS?
How can I get rid of the error?
Extra points, the server.log file is also writing [INFO] entries, where can I turn them off?
Looks like some old transaction to MSSQL database is still in transaction logs and could not be recovered. It looks like XA is not configured on your database server.
If you are still using that MSSQL server, try to configure XA support, if you don't use it any more you can try to stop WAS CE server and remove old transaction logs, which should be in /var/txlog.
For logging configuration check these two links: Logging in WAS CE and Application logging in WebSphere Application Server Community Edition
I have a Spring MVC project deployed on a TomCat server and I keep getting an issue with the connection to the database. After several hours, when a user tries to login they will be met with a 500 error and this message:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException: The last packet successfully received from the server was 75,026,904 milliseconds ago. The last packet sent successfully to the server was 75,031,521 milliseconds ago. is longer than the server configured value of 'wait_timeout'.
I believe the issue is because TomCat thinks the connection to MySQL is still open, however MySQL closes the connection after 8 hours. Once you refresh the page after getting this error, everything works fine.
My question is, is there a way to have the NamedParameterJdbcTemplate, that I am using to query the database, open and close a connection each time it is used rather than maintaining one persistent connection? Or is there a better way to solve this problem?
Perhaps setting autoReconnect=true? I am trying this now, but it will take several hours before I know if it worked.
Assuming you're using Tomcat's connection pooling, you can set your pool to testOnBorrow="true" and validationQuery="SELECT 1 FROM my_test_table". This way the connection will be checked before it's checked out by a thread. If it's closed, another one would be opened and given to the thread servicing your request. You can read the documentation of the options provided by Tomcat here.
I have a java web application that connects to a MSSQL 2005 database using Hibernate.
As the connnection to the DB from my application is not critical I wanted to test how the application behaved when the database was unavailable.
When I stop the SQL services and run through a part of the web application that runs queries on the database, my application hangs for about 30 seconds that then continues to function as normal.
As expected the error in the logs is:
2012-08-13 16:33:04,974 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 08S01
2012-08-13 16:33:04,974 ERROR [JDBCExceptionReporter] The TCP/IP connection to the host bonnie.uk, port 1433 has failed. Error: "Connection refused. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
Does anyone know how I can reduce the hangtime of the application?
Thanks
Shaw
As you mentioned that it's a web application, I suppose you are using a DataSource provided by your container (Tomcat, JBoss AS, ...), right? Right?? :-)
If that's the case, then your container certainly has a way to configure this. For JBoss AS, this would be "blocking-timeout-millis".