LP#1379824 Make PermaCrud.js disconnect() actually disconnect
authorDan Wells <dbw2@calvin.edu>
Thu, 9 Oct 2014 21:32:42 +0000 (17:32 -0400)
committerBen Shum <bshum@biblio.org>
Fri, 10 Oct 2014 19:05:33 +0000 (15:05 -0400)
The disconnect() method in PermaCrud.js was meant to wrap the
underlying session disconnect, but it never actually disconnected
the session.  This could lead to problems in long-living PermaCrud
objects, as they may think they are still connected when they are not
(the session remote_id is never cleared).

Also, remove a couple (now redundant) manual session.disconnect() calls.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Yamil Suarez <yamil@yamil.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/web/js/dojo/openils/PermaCrud.js

index c284c65..2df2fa1 100644 (file)
@@ -60,13 +60,11 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
         },
 
         disconnect : function ( onerror ) {
+            // session.disconnect() does not return any indication of success,
+            // so we must simply assume it worked
+            this.session.disconnect();
             this.connected = false;
             return true;
-            // disconnect returns nothing, which is null, which is not true, cause the following to always run ... arg.
-            if (!this.session.disconnect()) {
-                if (onerror) onerror(this.session);
-                return false;
-            }
         },
 
         _session_request : function ( args /* hash */, commitOnComplete /* set to true, else no */ ) {
@@ -82,7 +80,6 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                 if (args.timeout && !args.oncomplete && !args.onresponse) { // pure sync call
                     args.oncomplete = function (r) {
                         me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth());
-                        me.session.disconnect();
                         me.disconnect();
                     };
                 } else if (args.oncomplete) { // there's an oncomplete, fire that, and then end the transaction
@@ -93,7 +90,6 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                             ret = orig_oncomplete(r);
                         } finally {
                             me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth());
-                            me.session.disconnect();
                             me.disconnect();
                         }
                         return ret;