1

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 -

One solution
Another solution

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?

Community
  • 1
  • 1
Steve Wall
  • 1,842
  • 5
  • 21
  • 50

1 Answers1

0

Figured out the problem. Brain dead developer. I neglected to check-in the fix and it didn't make it into the war created by our build environment. Once I checked in the Datasource.groovy, all was groovy and I didn't see the timeout exception this morning. The above solution works.

I'm still confused why I didn't see debug message when the validationQuery ran. Does anyone know the proper log4j entry to see the validationQuery in the logs?

Steve Wall
  • 1,842
  • 5
  • 21
  • 50