Skip to content
This repository

Abort hooks if client disconnects and ignore further callbacks after timeout #175

Merged
merged 1 commit into from about 2 years ago

2 participants

Steve Freegard Matt Sergeant
Steve Freegard
Collaborator

No description provided.

Matt Sergeant baudehlo merged commit 6dc65b5 into from April 02, 2012
Matt Sergeant baudehlo closed this April 02, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 30, 2012
Steve Freegard Abort hooks if client disconnects and ignore further callbacks after …
…timeout
6416762
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 23 additions and 4 deletions. Show diff stats Hide diff stats

  1. 27  plugins.js
27  plugins.js
@@ -161,6 +161,14 @@ plugins._register_plugin = function (plugin) {
161 161
 }
162 162
 
163 163
 plugins.run_hooks = function (hook, object, params) {
  164
+    // Bail out if the client has disconnected
  165
+    if (object.constructor.name === 'Connection' && object.disconnected) {
  166
+        if (hook != 'log') {
  167
+            object.logdebug('aborting ' + hook + ' hook as client has disconnected');
  168
+        }
  169
+        return;
  170
+    }
  171
+
164 172
     if (hook != 'log')
165 173
         object.logdebug("running " + hook + " hooks");
166 174
     
@@ -191,18 +199,28 @@ plugins.run_hooks = function (hook, object, params) {
191 199
 };
192 200
 
193 201
 plugins.run_next_hook = function(hook, object, params) {
  202
+    // Bail if client has disconnected
  203
+    if (object.constructor.name === 'Connection' && object.disconnected) {
  204
+        object.logdebug('aborting ' + hook + ' hook as client has disconnected');
  205
+        return;
  206
+    }
194 207
     var called_once = 0;
195 208
     var timeout_id;
196  
-    
  209
+    var timed_out = false;
197 210
     var item;
198 211
     var callback = function(retval, msg) {
199 212
         if (timeout_id) clearTimeout(timeout_id);
200  
-        
201  
-        if (called_once) {
202  
-            if (hook != 'log')
  213
+        // Bail if client has disconnected
  214
+        if (object.constructor.name === 'Connection' && object.disconnected) {
  215
+            object.logdebug('ignoring ' + item[0].name + ' plugin callback as client has disconnected');
  216
+            return;
  217
+        }
  218
+        if (called_once && hook != 'log') {
  219
+            if (!timed_out) {
203 220
                 object.logerror(item[0].name + ' plugin ran callback multiple times - ignoring subsequent calls');
204 221
                 // Write a stack trace to the log to aid debugging
205 222
                 object.logerror((new Error).stack);
  223
+            }
206 224
             return;
207 225
         }
208 226
         called_once++;
@@ -269,6 +287,7 @@ plugins.run_next_hook = function(hook, object, params) {
269 287
 
270 288
     if (item[0].timeout && hook != 'log') {
271 289
         timeout_id = setTimeout(function () {
  290
+            timed_out = true;
272 291
             object.logcrit("Plugin " + item[0].name + 
273 292
                 " timed out on hook " + hook + " - make sure it calls the callback");
274 293
             callback(constants.denysoft, "plugin timeout");
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.