Skip to content

Commit

Permalink
avoid race to set ws.onclose callback
Browse files Browse the repository at this point in the history
between stop_channels and ws_closed_late
  • Loading branch information
minrk committed Jan 13, 2017
1 parent 3fb26ad commit f587b01
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion notebook/static/services/kernels/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define([
this.id = null;
this.name = name;
this.ws = null;
this._stopping = false;

this.kernel_service_url = kernel_service_url;
this.kernel_url = null;
Expand Down Expand Up @@ -507,7 +508,7 @@ define([
this.ws.onerror = ws_error;
// switch from early-close to late-close message after 1s
setTimeout(function() {
if (that.ws !== null) {
if (that.ws !== null && !that._stopping) {
that.ws.onclose = ws_closed_late;
}
}, 1000);
Expand Down Expand Up @@ -578,11 +579,14 @@ define([
*/
var that = this;
var close = function () {
that._stopping = false;
if (that.ws && that.ws.readyState === WebSocket.CLOSED) {
that.ws = null;
}
};
if (this.ws !== null) {
// flag to avoid races with on_close_late
this._stopping = true;
if (this.ws.readyState === WebSocket.OPEN) {
this.ws.onclose = close;
this.ws.close();
Expand Down

0 comments on commit f587b01

Please sign in to comment.