fixed bug 36274: abandoned connection in SessionListener
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 19 Jun 2017 15:16:26 +0200
changeset 32244 443c3cdbf841
parent 32243 a3af497e64de
child 32245 9e8fc20abd3f
fixed bug 36274: abandoned connection in SessionListener

Detach connection from current thread to allow it to be properly returned
to pool.

This is required whever the thread doing the actio is not handling an standard
request.
src/org/openbravo/erpCommon/security/SessionListener.java
--- a/src/org/openbravo/erpCommon/security/SessionListener.java	Fri Jun 16 12:57:27 2017 +0200
+++ b/src/org/openbravo/erpCommon/security/SessionListener.java	Mon Jun 19 15:16:26 2017 +0200
@@ -87,6 +87,8 @@
             .deactivate((ConnectionProvider) event.getServletContext()
                 .getAttribute("openbravoPool"), sessionId);
         SessionListener.context = null;
+        // detaching db connection from thread so can it be returned to pool
+        SessionInfo.init();
         log.info("Deactivated session: " + sessionId);
       } catch (ServletException e1) {
         log.error(e1.getMessage(), e1);
@@ -158,7 +160,6 @@
       activeHttpSessions.add(event.getSession());
     }
 
-
     if (RequestContext.get().getRequest() != null
         && AuthenticationManager.isStatelessRequest(RequestContext.get().getRequest())) {
       final String errorLog = RequestContext.get().getRequest().getRequestURL() + " "
@@ -199,6 +200,9 @@
       log.debug("Closed session" + sessionId);
     } catch (Exception e) {
       log.error("Error closing session:" + sessionId, e);
+    } finally {
+      // detaching db connection from thread so can it be returned to pool
+      SessionInfo.init();
     }
   }