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