Skip to content
This repository
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors
Mar 30, 2012
Steve Freegard smfreegard Abort hooks if client disconnects and ignore further callbacks after …
…timeout
6416762
Apr 02, 2012
Matt Sergeant Merge pull request #175 from smfreegard/master
Abort hooks if client disconnects and ignore further callbacks after timeout
6dc65b5

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

  1. +23 4 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");

No commit comments for this range

Something went wrong with that request. Please try again.