title: Idle In transaction after select statement using Postgres and Hibernate(Grails)
body: <p>I am using Grails 1.3.7 connected to Postgres 8.4
  We are running some functional tests of our application and we ran into a problem.
  After few minutes all of the connections we have to the database are  In Transaction and requests are timing out.
  I've tried determining what is going on using query from <a href="http://ghostwritten-insomnia.blogspot.com/2011/01/postgres-deadlock-debugging.html" rel="nofollow">Ghostwritten Insomnia</a> and all I got were some Exclusive Locks and Access Share Locks. According to <a href="http://www.postgresql.org/docs/8.4/static/explicit-locking.html" rel="nofollow">Postgres Docs</a> they work together and there should be nothing special about them. Well nothing special apart from the fact they stay on until I restart Tomcat or kill connections.
  I've enabled logging and tried to analyze them as described by Depesz on <a href="http://www.depesz.com/index.php/2008/08/28/hunting-idle-in-transactions/" rel="nofollow">his blog</a> but I have found no long running statements. I was able to determine last statements of the connections which are Idle in transaction, and it was a simple select, what more - it was finished fine [at least so the logs say].</p>
  
  <pre><code>2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) LOG:  duration: 0.111 ms  parse &lt;unnamed&gt;: select questdefin0_.id as id23_0_, questdefin0_.version as version23_0_, questdefin0_.cev_from as cev3_23_0_, questdefin0_.cev_to as cev4_23_0_, questdefin0_.description as descript5_23_0_, questdefin0_.duration as duration23_0_, questdefin0_.level_from as level7_23_0_, questdefin0_.level_to as level8_23_0_, questdefin0_.name as name23_0_, questdefin0_.pack_id as pack10_23_0_, questdefin0_.type as type23_0_, questdefin0_.travel_zone_id as travel13_23_0_, questdefin0_.class as class23_0_ from quest_definition questdefin0_ where questdefin0_.id=$1
  2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) LOG:  duration: 0.095 ms  bind &lt;unnamed&gt;: select questdefin0_.id as id23_0_, questdefin0_.version as version23_0_, questdefin0_.cev_from as cev3_23_0_, questdefin0_.cev_to as cev4_23_0_, questdefin0_.description as descript5_23_0_, questdefin0_.duration as duration23_0_, questdefin0_.level_from as level7_23_0_, questdefin0_.level_to as level8_23_0_, questdefin0_.name as name23_0_, questdefin0_.pack_id as pack10_23_0_, questdefin0_.type as type23_0_, questdefin0_.travel_zone_id as travel13_23_0_, questdefin0_.class as class23_0_ from quest_definition questdefin0_ where questdefin0_.id=$1
  2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) DETAIL:  parameters: $1 = '17935'
  2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) LOG:  execute &lt;unnamed&gt;: select questdefin0_.id as id23_0_, questdefin0_.version as version23_0_, questdefin0_.cev_from as cev3_23_0_, questdefin0_.cev_to as cev4_23_0_, questdefin0_.description as descript5_23_0_, questdefin0_.duration as duration23_0_, questdefin0_.level_from as level7_23_0_, questdefin0_.level_to as level8_23_0_, questdefin0_.name as name23_0_, questdefin0_.pack_id as pack10_23_0_, questdefin0_.type as type23_0_, questdefin0_.travel_zone_id as travel13_23_0_, questdefin0_.class as class23_0_ from quest_definition questdefin0_ where questdefin0_.id=$1
  2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) DETAIL:  parameters: $1 = '17935'
  2012-01-03 21:02:57.397 CET ogsuser@ogs 4294 127.0.0.1(34282) LOG:  duration: 0.052 ms
  </code></pre>
  
  <p>I went through the logfiles of postgres looking for other queries with id 17935 but I didn't find anything suspicious. And nothing at the same [or similar] time as this query.</p>
  
  <p>I've checked all of the IDLE In Transaction connections and I have found that all of them had the same last statement executed as the last one. Most of them had different IDs, few had the same, but they were executed in a very different moment, so I doubt this is the root cause. </p>
  
  <p>I've also checked logs on Tomcat. Nothing special there. The last thing done is the hibernate query and then nothing else.</p>
  
  <p>I've checked connection pool settings, it checks the connection after release and when idle to be sure that connections are ok.</p>
  
  <p>I've restarted tomcat and run the test again. After few minutes I ended up with all connections IDLE in transaction. This time different queries, again nothing I would consider weird. Just a simple select statement.</p>
  
  <p>So.. now the question part.
  Is there anything obvious I am missing? Some easy fix I could apply, setting or something...
  I am not sure where should I go now with this, what is the next step I should take to solve it.</p>
  
  <p>EDIT:
  To make things clear. This is a grails app deployed on tomcat. We are using controller actions as "REST like" endpoints. Integration and unit tests run fine. We are doing functional tests at the moment using Soapui and 5 threads running a simple scenario, simulating user behavior. </p>