Commit f0e1d504 authored by Arthur Edelstein's avatar Arthur Edelstein
Browse files

Bug #15510: Detach event watchers when finished

parent 6f5b6ea7
......@@ -129,7 +129,7 @@ let getCircuitStatusByID = function* (aController, circuitID) {
// corresponding circuit. Whenever the first stream on a new circuit is seen,
// looks up u+p and records the node data in the credentialsToNodeDataMap.
let collectIsolationData = function (aController) {
aController.watchEvent(
return aController.watchEvent(
"STREAM",
streamEvent => streamEvent.StreamStatus === "SENTCONNECT",
streamEvent => Task.spawn(function* () {
......@@ -313,10 +313,13 @@ let syncDisplayWithSelectedTab = (function() {
// A reference to this function (called createTorCircuitDisplay) is exported as a global.
let setupDisplay = function (host, port, password, enablePrefName) {
let myController = null,
stopCollectingIsolationData = null,
stop = function() {
if (myController) {
syncDisplayWithSelectedTab(false);
myController.close();
if (stopCollectingIsolationData) {
stopCollectingIsolationData();
}
myController = null;
}
},
......@@ -326,16 +329,20 @@ let setupDisplay = function (host, port, password, enablePrefName) {
// An error has occurred.
logger.eclog(5, err);
logger.eclog(5, "Disabling tor display circuit because of an error.");
myController.close();
stop();
});
syncDisplayWithSelectedTab(true);
collectIsolationData(myController);
stopCollectingIsolationData = collectIsolationData(myController);
}
};
try {
let unbindPref = bindPrefAndInit(enablePrefName, on => { if (on) start(); else stop(); });
// When this chrome window is unloaded, we need to unbind the pref.
window.addEventListener("unload", unbindPref);
window.addEventListener("unload", function () {
unbindPref();
stop();
});
} catch (e) {
logger.eclog(5, "Error: " + e.message + "\n" + e.stack);
}
......
......@@ -606,9 +606,10 @@ event.messageToData = function (type, message) {
// __event.watchEvent(controlSocket, type, filter, onData)__.
// Watches for a particular type of event. If filter(data) returns true, the event's
// data is pass to the onData callback.
// data is pass to the onData callback. Returns a zero arg function that
// stops watching the event.
event.watchEvent = function (controlSocket, type, filter, onData) {
controlSocket.addNotificationCallback(new RegExp("^650." + type, "i"),
return controlSocket.addNotificationCallback(new RegExp("^650." + type, "i"),
function (message) {
let data = event.messageToData(type, message);
if (filter === null || filter(data)) {
......@@ -635,9 +636,8 @@ tor.controller = function (host, port, password, onError) {
return { getInfo : key => info.getInfo(socket, key),
getInfoMultiple : keys => info.getInfoMultiple(socket, keys),
getConf : key => info.getConf(socket, key),
watchEvent : function (type, filter, onData) {
event.watchEvent(socket, type, filter, onData);
},
watchEvent : (type, filter, onData) =>
event.watchEvent(socket, type, filter, onData),
isOpen : () => isOpen,
close : () => { isOpen = false; socket.close(); }
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment