[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser] branch tor-browser-102.4.0esr-12.0-1 updated: fixup! Bug 40933: Add tor-launcher functionality
This is an automated email from the git hooks/post-receive script.
pierov pushed a commit to branch tor-browser-102.4.0esr-12.0-1
in repository tor-browser.
The following commit(s) were added to refs/heads/tor-browser-102.4.0esr-12.0-1 by this push:
new 8f318354ad30 fixup! Bug 40933: Add tor-launcher functionality
8f318354ad30 is described below
commit 8f318354ad30d4e56eee5aea4dc0e568dd59916b
Author: Pier Angelo Vendrame <pierov@xxxxxxxxxxxxxx>
AuthorDate: Mon Oct 24 11:09:57 2022 +0200
fixup! Bug 40933: Add tor-launcher functionality
Bug 41385: BootstrapError is never notified
Also, cleaned TorProcessDidNotStart, that is never actually used and
some other possible improvements on error reporting.
---
.../tor-launcher/TorBootstrapRequest.jsm | 56 +++++++++++-----------
.../components/tor-launcher/TorMonitorService.jsm | 31 ++++++++----
toolkit/components/tor-launcher/TorProcess.jsm | 23 ++-------
3 files changed, 51 insertions(+), 59 deletions(-)
diff --git a/toolkit/components/tor-launcher/TorBootstrapRequest.jsm b/toolkit/components/tor-launcher/TorBootstrapRequest.jsm
index 4f0ae240b31d..e999d5c3f62c 100644
--- a/toolkit/components/tor-launcher/TorBootstrapRequest.jsm
+++ b/toolkit/components/tor-launcher/TorBootstrapRequest.jsm
@@ -39,7 +39,7 @@ class TorBootstrapRequest {
this._timeoutID = null;
}
- async observe(subject, topic, data) {
+ observe(subject, topic, data) {
const obj = subject?.wrappedJSObject;
switch (topic) {
case TorTopics.BootstrapStatus: {
@@ -59,17 +59,8 @@ class TorBootstrapRequest {
break;
}
case TorTopics.BootstrapError: {
- // first stop our bootstrap timeout before handling the error
- clearTimeout(this._timeoutID);
-
- await TorProtocolService.stopBootstrap();
-
- const message = obj.message;
- const details = obj.details;
- if (this.onbootstraperror) {
- this.onbootstraperror(message, details);
- }
- this._bootstrapPromiseResolve(false);
+ console.info("TorBootstrapRequest: observerd TorBootstrapError", obj);
+ this._stop(obj?.message, obj?.details);
break;
}
}
@@ -91,41 +82,48 @@ class TorBootstrapRequest {
// optionally cancel bootstrap after a given timeout
if (this.timeout > 0) {
this._timeoutID = setTimeout(async () => {
- await TorProtocolService.stopBootstrap();
- if (this.onbootstraperror) {
- this.onbootstraperror(
- "Tor Bootstrap process timed out",
- `Bootstrap attempt abandoned after waiting ${this.timeout} ms`
- );
- }
- this._bootstrapPromiseResolve(false);
+ this._timeoutID = null;
+ // TODO: Translate, if really used
+ await this._stop(
+ "Tor Bootstrap process timed out",
+ `Bootstrap attempt abandoned after waiting ${this.timeout} ms`
+ );
}, this.timeout);
}
// wait for bootstrapping to begin and maybe handle error
- TorProtocolService.connect().catch(async err => {
- clearTimeout(this._timeoutID);
- // stopBootstrap never throws, at the moment
- await TorProtocolService.stopBootstrap();
- if (this.onbootstraperror) {
- this.onbootstraperror(err.message, "");
- }
- this._bootstrapPromiseResolve(false);
+ TorProtocolService.connect().catch(err => {
+ this._stop(err.message, "");
});
}).finally(() => {
// and remove ourselves once bootstrap is resolved
Services.obs.removeObserver(this, TorTopics.BootstrapStatus);
Services.obs.removeObserver(this, TorTopics.BootstrapError);
+ this._bootstrapPromise = null;
});
return this._bootstrapPromise;
}
async cancel() {
- clearTimeout(this._timeoutID);
+ await this._stop();
+ }
+
+ // Internal implementation. Do not use directly, but call cancel, instead.
+ async _stop(message, details) {
+ // first stop our bootstrap timeout before handling the error
+ if (this._timeoutID !== null) {
+ clearTimeout(this._timeoutID);
+ this._timeoutID = null;
+ }
+ // stopBootstrap never throws
await TorProtocolService.stopBootstrap();
+ if (this.onbootstraperror && message) {
+ this.onbootstraperror(message, details);
+ }
+
this._bootstrapPromiseResolve(false);
}
}
diff --git a/toolkit/components/tor-launcher/TorMonitorService.jsm b/toolkit/components/tor-launcher/TorMonitorService.jsm
index 201ac6275c56..881f4a5a7355 100644
--- a/toolkit/components/tor-launcher/TorMonitorService.jsm
+++ b/toolkit/components/tor-launcher/TorMonitorService.jsm
@@ -47,7 +47,6 @@ const Preferences = Object.freeze({
const TorTopics = Object.freeze({
BootstrapError: "TorBootstrapError",
HasWarnOrErr: "TorLogHasWarnOrErr",
- ProcessDidNotStart: "TorProcessDidNotStart",
ProcessExited: "TorProcessExited",
ProcessIsReady: "TorProcessIsReady",
ProcessRestarted: "TorProcessRestarted",
@@ -191,8 +190,17 @@ const TorMonitorService = {
await this._controlTor();
Services.obs.notifyObservers(null, TorTopics.ProcessRestarted);
};
- await this._torProcess.start();
- if (!this._torProcess.isRunning) {
+ try {
+ await this._torProcess.start();
+ if (!this._torProcess.isRunning) {
+ this._torProcess = null;
+ return false;
+ }
+ } catch (e) {
+ // TorProcess already logs the error.
+ this._bootstrapErrorOccurred = true;
+ this._lastWarningPhase = "startup";
+ this._lastWarningReason = e.toString();
this._torProcess = null;
return false;
}
@@ -222,11 +230,9 @@ const TorMonitorService = {
ControlConnTimings.timeoutMS
) {
let s = TorLauncherUtil.getLocalizedString("tor_controlconn_failed");
- TorLauncherUtil.notifyUserOfError(
- s,
- null,
- TorTopics.ProcessDidNotStart
- );
+ this._bootstrapErrorOccurred = true;
+ this._lastWarningPhase = "startup";
+ this._lastWarningReason = s;
logger.info(s);
} else {
delayMS *= 2;
@@ -432,8 +438,13 @@ const TorMonitorService = {
this._lastWarningPhase = statusObj.TAG;
this._lastWarningReason = statusObj.REASON;
- const msg = TorLauncherUtil.getLocalizedString("tor_bootstrap_failed");
- TorLauncherUtil.notifyUserOfError(msg, details, TorTopics.BootstrapError);
+ const message = TorLauncherUtil.getLocalizedString(
+ "tor_bootstrap_failed"
+ );
+ Services.obs.notifyObservers(
+ { message, details },
+ TorTopics.BootstrapError
+ );
}
},
diff --git a/toolkit/components/tor-launcher/TorProcess.jsm b/toolkit/components/tor-launcher/TorProcess.jsm
index a23fd324efff..3dd194817d0a 100644
--- a/toolkit/components/tor-launcher/TorProcess.jsm
+++ b/toolkit/components/tor-launcher/TorProcess.jsm
@@ -32,10 +32,6 @@ const TorProcessStatus = Object.freeze({
Exited: 3,
});
-const TorProcessTopics = Object.freeze({
- ProcessDidNotStart: "TorProcessDidNotStart",
-});
-
// Logger adapted from CustomizableUI.jsm
XPCOMUtils.defineLazyGetter(this, "logger", () => {
const { ConsoleAPI } = ChromeUtils.import(
@@ -82,9 +78,7 @@ class TorProcess {
this._status = TorProcessStatus.Unknown;
try {
- if (!this._makeArgs()) {
- return;
- }
+ this._makeArgs();
this._addControlPortArg();
this._addSocksPortArg();
@@ -149,11 +143,7 @@ class TorProcess {
this._status = TorProcessStatus.Exited;
this._torProcess = null;
logger.error("startTor error:", e);
- Services.obs.notifyObservers(
- null,
- TorProcessTopics.ProcessDidNotStart,
- null
- );
+ throw e;
}
}
@@ -284,12 +274,7 @@ class TorProcess {
[details],
1
);
- TorLauncherUtil.notifyUserOfError(
- err,
- null,
- TorProcessTopics.ProcessDidNotStart
- );
- return false;
+ throw new Error(err);
}
const torrcDefaultsFile = TorLauncherUtil.getTorFile(
@@ -319,8 +304,6 @@ class TorProcess {
this._args.push(geoip6File.path);
this._args.push("HashedControlPassword");
this._args.push(hashedPassword);
-
- return true;
}
_addControlPortArg() {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits