From e2c0b6b5b770f4f38c5aae1b31cf07f325616aef Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Thu, 8 Dec 2016 16:05:28 -0800 Subject: [PATCH] Fix a subtle async bug in processing comm messages. Basically, message processing did not wait for any promises a comm message handler may return to resolve, because comms were not set up to resolve return values of message handlers. --- notebook/static/services/kernels/comm.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/notebook/static/services/kernels/comm.js b/notebook/static/services/kernels/comm.js index 6326a3766..6f406807b 100644 --- a/notebook/static/services/kernels/comm.js +++ b/notebook/static/services/kernels/comm.js @@ -128,12 +128,9 @@ define([ } this.comms[content.comm_id] = this.comms[content.comm_id].then(function(comm) { - try { - comm.handle_msg(msg); - } catch (e) { - console.log("Exception handling comm msg: ", e, e.stack, msg); - } - return comm; + return (Promise.resolve(comm.handle_msg(msg)) + .catch(utils.reject('Exception handling comm message')) + .then(function() {return comm;})); }); return this.comms[content.comm_id]; }; @@ -193,7 +190,7 @@ define([ var callback = this['_' + key + '_callback']; if (callback) { try { - callback(msg); + return callback(msg); } catch (e) { console.log("Exception in Comm callback", e, e.stack, msg); } @@ -201,7 +198,7 @@ define([ }; Comm.prototype.handle_msg = function (msg) { - this._callback('msg', msg); + return this._callback('msg', msg); }; Comm.prototype.handle_close = function (msg) {