From: Darren Date: Sun, 1 Sep 2013 13:43:25 +0000 (+0100) Subject: WebsocketRpc: Cleanup callbacks before exceptions occur X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a6b1c06259d566f74156f356b1bb4109ad65a84d;p=KiwiIRC.git WebsocketRpc: Cleanup callbacks before exceptions occur --- 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') {