Index: openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs.tcl,v
diff -u -r1.116 -r1.117
--- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl	18 Dec 2018 21:25:21 -0000	1.116
+++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl	22 Dec 2018 09:39:46 -0000	1.117
@@ -699,6 +699,9 @@
 
         @param dbn The database name to use.  If empty_string, uses the default database.
     } {
+        # we need the state array still for transaction handling
+        upvar "#0" [db_state_array_name_is -dbn $dbn] db_state
+
         set pools [db_available_pools $dbn]
         set currentHandles [ns_db currenthandles]
 
@@ -707,6 +710,12 @@
                 foreach {handle active} [dict get $currentHandles $pool] {
                     #ns_log notice "### FOUND pool $pool handle $handle active $active"
                     if {$active eq 0} {
+                        # Don't release handles which are part of a transaction.
+                        if { [info exists db_state(transaction_level,$handle)]
+                             && $db_state(transaction_level,$handle) > 0
+                         } {
+                            continue
+                        }
                         set start_time [expr {[clock clicks -microseconds]/1000.0}]
                         ns_db releasehandle $handle
                         #ns_log notice "### AFTER releasehandle [ns_db currenthandles $pool]"