I have java application that connect to mysql on docker. when i run load test to save and update data to mysql, first it run corectly but, after a while i got the
Caused by: java.net.NoRouteToHostException: Cannot assign requested address (Address not available)
and program exit immediately.
my program connect to mysql by hibernate and i used the following code to interact with database:
Session curentSession = sessionFactory.getCurrentSession();
curentTransaction = curentSession.beginTransaction();
curentSession.update(entity);
curentTransaction.commit();
It seem that when hibernate open session with getcurrentSession(), close it after transaction commit, but the tcp connection is still open with status of "TIME_WAIT" so when i run netstat -natp i got the huge number of connection to 3306 (mysql port). so i have two solution:
change the design of my connection to database that not close and reopen connection in each transaction.
change the time of connection wait in status "time_wait" with:
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
In addition i found that change the tcp_fin_timeout is not good solution in my case. i change the dataSource from DriverManagerDataSource to HikariDataSource and used the maximumPoolSize to manage the connection to mysql database.
so the problem of huge connection to mysql database gone away. ;)
good luck
Related
I have registered a Linux machine as runner in my gitlab and tried to execute my scripts there.
While executing I got an error for database connection
Issue : java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
When I connect from my local machine (Windows 7 & 10) it is working fine.
Attempts:
Tried to connect using jtds but I'm getting some other unknown issue.
Checked few other answers and they have provided that it could be because of firewall enabled but since we did not have full access to that db server , I could not disable and check.(Could this be the issue?)
My Connection code :
ConURL = "jdbc:oracle:thin:#" + ConstructSQLConnectionURL(host,sid,port);
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(ConURL, dbUserName, dbPassword);
I am stuck with this issue and blocked from executing pipeline.
Can anyone let me know what could be the possible reason for this and help me with this?
Thanks in advance
It appears to be a network connectivity issue. I'd start with local firewalls on each system. Can you ping the database from the client? If not, look for network routing or firewall blockers. Also look at host-based firewalls, or confirm with the DBA whether there is something like valid node checking in place to limit database clients.
We are using camunda with RDS/MySql as DB. It works fine but then sometimes it says DB is closed and so throws the ProcessEngine Exception.
Here is what I understood from our config and logs:
We have 5active connections at any time in our pool (Specified in datasource config)
There was a scenario where it was closed.
We saw error like:
Request received Context path: /engine-rest Request received Path
Info: /user PathInfo: /user ExceptionHandler:
org.camunda.bpm.engine.ProcessEngineException: Process engine
persistence exception at
org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.rethrow(CommandInvocationContext.java:148)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:173)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
...... Caused by: org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
No operations allowed after connection closed. The error may exist in
org/camunda/bpm/engine/impl/mapping/entity/User.xml The error may
involve
org.camunda.bpm.engine.impl.persistence.entity.UserEntity.selectUserByQueryCriteria
The error occurred while executing a query SQL: select distinct RES.*
from ACT_ID_USER RES
order by RES.ID_ asc LIMIT ? OFFSET ? Cause:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
No operations allowed after connection closed.
Our tomcat props specify: minIdle = 5;
My best guess: Its closed on server but we are maintaining locally due to the above property.
Per tomcat doc (https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html):
testOnBorrow = true;
validationQuery = "select 1";
The two props should fix it as it validates the connection.
Question I am trying to figure out:
How can I repro this issue? Apart from keeping connection it idle for several hours, the scenario where this happened.
Does the AWS RDS server close the connection? If so, can we control it?
As mentioned by #Zelldon, the connection timeout can be reduced and then we could try it. It works as expected.
Just to be sure, I ran two instances of camunda, one with this fix and other without. Could see that the fix worked.
Regarding RDS, it does close the connection but I could not find any documentation on it.
I am using connection pooling of tomcat with oracle database. It is working fine, but when i use my application after a long time it is giving error that "connection reset". I am getting this error because of physical connection at oracle server closed before logical connection closed at tomcat datasource. So before getting the connection from datasource i am checking the connection validity with isValid(0) method of connection object which gives false if the physical connection was closed. But i don't know how to remove that invalid connection object from the pool.
This could be because on the db server, there is a timeout to not allow connections to live beyond a set time, or to die if it does not receive something saying it is still valid. One way to fix this is to turn on keepalives. These basically ping the db server saying that they are still valid connections.
This is a pretty good link on Tomcats DBCP configurations. Take a look at the section titled "Preventing dB connection pool leaks". That looks like it may be a good place to start.
I used validatationquery while configuring the datasource in server.xml file. It is going to check the validity of the connection by executing the query at database before giving to the application.
for Oracle
validationQuery="/* select 1 from dual */"
for MySql
validationQuery="/* ping */"
Try closing it and opening it if it's invalid. I mean u would reinitialize it in this way so u won't need to remove it from the pool and reuse it.
If we want to dispose an ill java.sql.connection from Tomcat jdbc connection pool,
we may do this explicitly in the program.
Unwrap it into an org.apache.tomcat.jdbc.pool.PooledConnection,
setDiscarded(true) and close the JDBC connection finally.
The ConnectionPool will remove the underlying connection once it has been returned.
(ConnectionPool.returnConnection(....))
e.g.
PooledConnection pconn = conn.unwrap(PooledConnection.class); pconn.setDiscarded(true);
conn.close();
I have a problem in establishing DB2 connection with wrong user-name/password. We have an application which runs on LAN on many systems using DB2 database located on my system as well as other systems.
Firstly I use this URL to create other system DB2 connection:
Connection con = DriverManager.getConnection("jdbc:db2://Rahulkcomputer:50000/XAN4", "rahulk", "dbirs#35");
this returns proper Connection object. Now when I change the URL to access my system DB2 connection with same user-name/password as (using same user-name/password is intensely done for checking error handling):
Connection con = DriverManager.getConnection("jdbc:db2://127.0.0.1:50000/XAN4", "rahulk", "dbirs#35");
This time it again returns the Connection object instead of throwing an SQLException specifying wrong user-name/password (due to my system's DB2 authentication is totally different from Rahulkcomputer's system)
After getting connection, I execute this query to check proper user name as explained in post:
Simple DB2 Query for connection validation
SELECT CURRENT SQLID FROM SYSIBM.SYSDUMMY1
(this returns "rahulk" in both cases)
Why DB2 created connection in 2nd case with wrong user-name/password (moreover when we close all the services of DB2 on Rahulkcomputer, even then I get the connection in 2nd case)?
Thanks in Advance.
You either created your database with the restrictive option or revoked the select right to sysibm from PUBLIC. The connection you had was fine, the access rights not. 42704 is DB2's way of saying "huh?", it did not recognize sysibm because you had no rights to see it.
I get the following error when I try to run my project:
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870080)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
Any ideas?
You're getting an ORA-12505 error ("TNS: listener could not resolve SID given in connection description."). This happens when the SID (System ID) of the database you wish to connect to isn't registered with Oracle's listener. If you can find the JDBC connection information, you may find something that matches this pattern:
jdbc:oracle:thin:[user]/[password]#[host]:[port]:[sid]
In this case, Oracle is telling you that [sid] does not exist on the server [host]. You may be connecting to the wrong server.
Connection refused means that the server is not allowing your client to connect. Double check the server settings and make sure your host is allowed to connect, at the very least.