From a6b1c06259d566f74156f356b1bb4109ad65a84d Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 1 Sep 2013 14:43:25 +0100 Subject: [PATCH] WebsocketRpc: Cleanup callbacks before exceptions occur --- client/assets/libs/engine.io.tools.js | 10 +++++++--- server/websocketrpc.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/assets/libs/engine.io.tools.js b/client/assets/libs/engine.io.tools.js index 8e7c264..e24ba24 100644 --- a/client/assets/libs/engine.io.tools.js +++ b/client/assets/libs/engine.io.tools.js @@ -225,7 +225,8 @@ var EngineioTools = { WebsocketRpc.prototype._onMessage = function(message_raw) { var self = this, packet, - returnFn; + returnFn, + callback; try { packet = JSON.parse(message_raw); @@ -239,10 +240,13 @@ var EngineioTools = { if (typeof this._rpc_callbacks[packet.id] !== 'function') return; - // Call and delete this callback once finished with it - this._rpc_callbacks[packet.id].apply(this, packet.response); + // Delete the callback before calling it. If any exceptions accur within the callback + // we don't have to worry about the delete not happening + callback = this._rpc_callbacks[packet.id]; delete this._rpc_callbacks[packet.id]; + callback.apply(this, packet.response); + } else if (this._isCall(packet)) { // Calls with an ID may be responded to if (typeof packet.id !== 'undefined') { diff --git a/server/websocketrpc.js b/server/websocketrpc.js index 9743018..1fa035a 100644 --- a/server/websocketrpc.js +++ b/server/websocketrpc.js @@ -122,7 +122,8 @@ WebsocketRpc.prototype.send = function(packet) { WebsocketRpc.prototype._onMessage = function(message_raw) { var self = this, packet, - returnFn; + returnFn, + callback; try { packet = JSON.parse(message_raw); @@ -136,10 +137,13 @@ WebsocketRpc.prototype._onMessage = function(message_raw) { if (typeof this._rpc_callbacks[packet.id] !== 'function') return; - // Call and delete this callback once finished with it - this._rpc_callbacks[packet.id].apply(this, packet.response); + // Delete the callback before calling it. If any exceptions accur within the callback + // we don't have to worry about the delete not happening + callback = this._rpc_callbacks[packet.id]; delete this._rpc_callbacks[packet.id]; + callback.apply(this, packet.response); + } else if (this._isCall(packet)) { // Calls with an ID may be responded to if (typeof packet.id !== 'undefined') { -- 2.25.1