@@ -733,10 +733,14 @@ public URL safeURL(HttpServletRequest request) {
733733 Shepherd myShepherd = new Shepherd (context );
734734 myShepherd .setAction ("MediaAsset.safeURL" );
735735 myShepherd .beginDBTransaction ();
736- URL u = safeURL (myShepherd , request );
737- myShepherd .rollbackDBTransaction ();
738- myShepherd .closeDBTransaction ();
739- return u ;
736+ // try/finally so a throw from safeURL(myShepherd, request) -- e.g. a JDO lazy-load/query
737+ // failure inside bestSafeAsset() -- cannot skip the close and leak the PersistenceManager.
738+ // Those leaks are the "MediaAsset.safeURL:begin" Shepherds stuck on dbconnections.jsp.
739+ try {
740+ return safeURL (myShepherd , request );
741+ } finally {
742+ myShepherd .rollbackAndClose ();
743+ }
740744 }
741745
742746 public URL safeURL () {
@@ -1191,6 +1195,10 @@ public void run() {
11911195 Shepherd myShepherd = new Shepherd (context );
11921196 myShepherd .setAction ("updateStandardChildrenBackground:" + tid );
11931197 myShepherd .beginDBTransaction ();
1198+ // try/finally so a throw from load/updateStandardChildren cannot skip the close and
1199+ // leak this background Shepherd. commit stays inside try; the finally rollback is a
1200+ // harmless no-op once the commit has succeeded.
1201+ try {
11941202 int ct = 0 ;
11951203 for (Integer id : ids ) {
11961204 ct ++;
@@ -1202,7 +1210,9 @@ public void run() {
12021210 "] completed " + kids .size () + " children for id=" + id );
12031211 }
12041212 myShepherd .commitDBTransaction ();
1205- myShepherd .closeDBTransaction ();
1213+ } finally {
1214+ myShepherd .rollbackAndClose ();
1215+ }
12061216 }
12071217 };
12081218 new Thread (rn ).start ();
0 commit comments