Environment - Grails 2.0.4, Oracle 11G
After a couple of hours of inactivity, reading from the database causes a java.net.SocketException: Connection timed out. Based on others suggests on solving this problem, I update the dataSource with properties to keep db connections alive. Here are a couple of solutions I looked at -
It appears the solution involves setting the appropriate values on the datasource. In my case, 2 datasources are involved. I'm trying to do a session keep-alive, to avoid the connection timeout. This appears to be accomplished by setting the validationQuery property and the testXXX properties. When a test is needed the validation query is run. I thought the below configuration would give me the desired results, but I'm still seeing the timeout. I cranked up the debugging
debug 'org.hibernate'
debug 'jdbc.sqlonly'
I would have expected to see the validationQuery run at some interval. Based on the "6000" ms value that was specified, I expected to see the validationQuery every 6 seconds. Here's the datasource specification. I tried this two ways. Specifying them within the "properties" closure and specifying them at the same level as "pooled".
dataSource_secondary {
logSql = true
pooled = true
properties {
maxActive = 5
maxIdle = 5
minIdle = 3
initialSize = 5
minEvictableIdleTimeMillis = 6000
timeBetweenEvictionRunsMillis = 6000
maxWait = 1000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
validationQuery = "select 1 from dual"
}
}
I also ran this in the debugger and added some code to BootStrap.groovy to get the context.
def ctx = servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT)
println 'Added a println allowing me to set a break point and inspect the context.'
"ctx" did have the expected values as specified in dataSource_secondary. Any ideas why I'm still getting the socket exception?