Tomcat connection pool, connection timeout - tomcat7

I have an application running on tomcat 7.0.65, and using org.apache.tomcat.jdbc.pool.DataSource
I have connection pool setup:
PoolProperties p = new PoolProperties();
p.setUrl("jdbc:oracle:thin:#....");
p.setDriverClassName("oracle.jdbc.OracleDriver");
p.setUsername("***");
p.setPassword("***");
p.setJmxEnabled(true);
p.setTestWhileIdle(false);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1 from dual");
p.setTestOnReturn(false);
p.setValidationInterval(30000);
p.setTimeBetweenEvictionRunsMillis(30000);
p.setMaxActive(100);
p.setInitialSize(10);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(60);
p.setMinEvictableIdleTimeMillis(30000);
p.setMinIdle(10);
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setName("jdbc/insurancePool");
DataSource asyncDS = new DataSource(p);
Everyday when I try to run the application I get connection timed out exception for the first couple of tries. I am not sure why this is happening. Does firewall have anything to do with this?

I had the same issue with MySql everyday morning. Then I found autoReconnect parameter which can be used with JDBC URL to fix this.
For example:
MYSQL_URL=jdbc:mysql://10.*.*.0:3306/ABC?autoReconnect=true

Issue resolved, found this link helpful Firewall Issues
I changed "minIdle" to 0 and also set sqlnet.expire_time parameter in the sqlnet.ora file to 0..
Hope this helps someone else..

Related

Spring boot - MasterReplicaTopologyRefresh - Unable to connect to 172.21.0.3:6379

I'm using Spring Boot to connect to Redis, every time I try to write into Redis I got this error MasterReplicaTopologyRefresh - Unable to connect to 172.21.0.3:6379, it's trying to contact the wrong server several times it sends 4 requests after 4 seconds.
Is there a way to stop or override the default host and port?
Thanks in advance
The issue came from readFrom(ReadFrom.MASTER) after removing it, it worked fine, when it is enabled the connection config keeps try to connect to the master
LettuceClientConfiguration lettuceClientConfiguration = LettuceClientConfiguration.builder()
//.readFrom(ReadFrom.MASTER)
.commandTimeout(Duration.ofSeconds(120))
.clientOptions(clusterClientOptions)
.build();

setting TopologyChangeAware on jdbc voltdb client

I am making a jdbc connection to voltdb, how to make this connection TopologyChangeAware. over here i am using Hikari.
Finally got answer
For now, the jdbc client does not have a TopologyChangeAware property, but there is a similar one called autoreconnect that we can put into your connection URL.
It is described in the docs here:usingvoltdb jdbc
It looks something like this:
Connection c = DriverManager.getConnection(
"jdbc:voltdb://svr1:21212,svr2:21212?autoreconnect=true");
When set to true, the jdbc client will automatically try to reconnect to any nodes that disconnect until they rejoin the cluster.

java.sql.SQLRecoverableException: Connection has been administratively disabled by console/admin command. Try later

When our application tries to connect Oracle database, this exception is thrown:
java.sql.SQLRecoverableException: Connection has been administratively disabled by console/admin command. Try later. java.lang.Exception: It was disabled at Tue Oct 20 23:55:14 CEST 2015
But, from Weblogic console the connection test returns OK.
Weblogic version: 12.1.3.0.0
Any explanation is welcome. Thanks
The reason the test works is because that is creating a connection and running a test query. That is not what your code is doing when it is using the data source in an ejb. The code is going through the connection pool and that is what has been marked as bad. There is no solution provided by Oracle that I have found except to: restart the server and that will re-enable the connection pool.
I suspect you have "Test connections on reserve" set because that is when this usually arises. What Weblogic does is: before it returns a connection from the pool it will run a test query, if the test query fails it waits and runs it one more time. If the query fails again it marks the connection as unhealthy. If all the connections in the pool become unhealthy it will mark the pool as disabled and gives you the error message you see: 'Connection has been administratively disabled by console/admin command. Try later.'
In regards to the 'Try Later' part of the error message, as far as I can tell Oracle is wrong about trying again later. I have never seen it recover later.
I'd like to share this article that help me out to understand better my problem:
https://www.techpaste.com/2012/09/connection-administratively-destroyed-reconnect-oracle-weblogic-server/
The “java.sql.SQLException: Connection has been administratively destroyed.” is expected:
the DB was shutdown; even if it was restarted later, the JDBC connection are pointing to DB processes
that have been destroyed.
You need to restart your WebLogic Server to recreate new JDBC connections.
All the current transactions are lost, as the database was shutdown.
High availability of your RDBMS is required to minimize this issue.
Is there any other error before that one ?
Maybe in the log you can find that connection is been closed.
You can avoid this by selecting "Test on Connection Reserve" in the datasource.

Teradata setLoginTimeout not working

I am building an app in extjs connecting to teradata at the back-end. It works fine locally but when deployed its giving
[Error 1277] [SQLState 08S01] Login time-out for Connection to server after 12seconds.
I am trying to increase the timeout now.
Class.forName("com.teradata.jdbc.TeraDriver");
DriverManager.setLoginTimeout(100);
Connection conn = DriverManager.getConnection(connectionString, "user", "pass");
Still I'm getting same time-out error after 12 seconds. It seems like setLoginTimeout didn't work. Where am I going wrong? Is there any other solution other than increasing time-out ?
P.S: For one server it worked fine now I changed only the server name to point to another server and I'm getting timeout.
The below link might help you.
http://forums.teradata.com/forum/connectivity/could-you-tell-me-the-reason-why-login-time-out

Setting Oracle 11g Session Timeout

After rebooting the server, the oracle connection from the Tomcat server times out every night. Prior to the reboot, the connection didn't timeout. Now, in the morning, the application throws a JDBC connection error while accessing the DB. Restarting Tomcat corrects the issue. I'm assuming that's due to the connections being re-established. I think, this is due to the Oracle DB timing out the session. How can the session timeout be disabled in Oracle 11g?
Thanks!
Steve
Config.groovy with dev and test omitted.
dataSource {
pooled = true
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
production {
dataSource {
driverClassName = "oracle.jdbc.driver.OracleDriver"
username = "XXXXX"
password = "XXXXXX"
dialect = "org.hibernate.dialect.Oracle10gDialect"
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:oracle:thin:#XXXXXX:1521:xxxx"
}
} }
That's generally controlled by the profile associated with the user Tomcat is connecting as.
SQL> SELECT PROFILE, LIMIT FROM DBA_PROFILES WHERE RESOURCE_NAME = 'IDLE_TIME';
PROFILE LIMIT
------------------------------ ----------------------------------------
DEFAULT UNLIMITED
SQL> SELECT PROFILE FROM DBA_USERS WHERE USERNAME = USER;
PROFILE
------------------------------
DEFAULT
So the user I'm connected to has unlimited idle time - no time out.
Adam has already suggested database profiles.
You could check the SQLNET.ORA file. There's an EXPIRE_TIME parameter but this is for detecting lost connections, rather than terminating existing ones.
Given it happens overnight, it sounds more like an idle timeout, which could be down to a firewall between the app server and database server. Setting the EXPIRE_TIME may stop that happening (as there'll be check every 10 minutes to check the client is alive).
Or possibly the database is being shutdown and restarted and that is killing the connections.
Alternatively, you should be able to configure tomcat with a validationQuery so that it will automatically restart the connection without a tomcat restart
This is likely caused by your application's connection pool; not an Oracle DBMS issue. Most connection pools have a validate statement that can execute before giving you the connection. In oracle you would want "Select 1 from dual".
The reason it started occurring after you restarted the server is that the connection pool was probably added without a restart and you are just now experiencing the use of the connection pool for the first time. What is the modification dates on your resource files that deal with database connections?
Validate Query example:
<Resource name="jdbc/EmployeeDB" auth="Container"
validationQuery="Select 1 from dual" type="javax.sql.DataSource" username="dbusername" password="dbpassword"
driverClassName="org.hsql.jdbcDriver" url="jdbc:HypersonicSQL:database"
maxActive="8" maxIdle="4"/>
EDIT:
In the case of Grails, there are similar configuration options for the grails pool. Example for Grails 1.2 (see release notes for Grails 1.2)
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost/yourDB"
driverClassName = "com.mysql.jdbc.Driver"
username = "yourUser"
password = "yourPassword"
properties {
maxActive = 50
maxIdle = 25
minIdle = 5
initialSize = 5
minEvictableIdleTimeMillis = 60000
timeBetweenEvictionRunsMillis = 60000
maxWait = 10000
}
}
I came to this question looking for a way to enable oracle session pool expiration based on total session lifetime instead of idle time.
Another goal is to avoid force closes unexpected to application.
It seems it's possible by setting pool validation query to
select 1 from V$SESSION
where AUDSID = userenv('SESSIONID') and sysdate-LOGON_TIME < 30/24/60
This would close sessions aging over 30 minutes in predictable manner that doesn't affect application.
Does the DB know the connection has dropped, or is the session still listed in v$session? That would indicate, I think, that it's being dropped by the network. Do you know how long it can stay idle before encountering the problem, and if that bears any resemblance to the TCP idle values (net.ipv4.tcp_keepalive_time, tcp_keepalive_probes and tcp_keepalive_interval from sysctl if I recall correctly)? Can't remember whether sysctl changes persist by default, but that might be something that was modified and then reset by the reboot.
Also you might be able to reset your JDBC connections without bouncing the whole server; certainly can in WebLogic, which I realise doesn't help much, but I'm not familiar with the Tomcat equivalents.
Check applications connection Pool settings, rather than altering any session timout settings on the oracle db. It's normal that they time out.
Have a look here:
http://grails.org/doc/1.0.x/guide/3.%20Configuration.html#3.3%20The%20DataSource
Are you sure that you have set the "pooled" parameter correctly?
Greetings,
Lars
EDIT:
Your config seems ok on first glimpse.
I came across this issue today. Maybe it is related to your pain:
"Infinite loop of exceptions if the application is started when the database is down for maintenance"

Resources