Skip to content

Loading…

Robustness changes from watching logs in Fennec #1042

Merged
merged 1 commit into from

2 participants

@AlexVallat
Collaborator

I've been testing in Fennec with the changes from a2626a9 and found some cases where errors sometimes occur with restarting Firefox, and toggling enabling and disabling the addon. These change add a little robustness to avoid those errors.

@Deathamns

I looked into it, and realized that the errors appear when you disable the extension when you view the list of the add-ons, not when disable/enable from the page of the add-on (this is why I didn't see the errors @gorhill saw).
So, the problem is that the button is null when you disable it from the list of the add-ons. Because of that the script will stop there, and won't register the unload event, which performs the cleanup tasks.
So, simply add an if button is null then return check, instead of unregistering the factory, because while that solves the httpobserver issue, it hides the bigger problem.

@AlexVallat
Collaborator

There is also a possible path where browser here is null, and that causes the same effect of stopping the script prematurely.

I didn't see the button issue you mention because on Fennec you can only disable and enable it from the addon page itself, not from the list of addons (there are no buttons there).

In my opinion, the factory unregistering should stay in any case, because it's a way to recover from any error that causes cleanup to fail. Without it, once cleanup fails, the addon will never work properly again until Firefox is restarted, so I think it's worth having.

If you are concerned about problem hiding, then I think the correct solution to that would be to log the very end of cleanup, and of startup, and if the end doesn't happen then we know something horrible has gone wrong. It would even be possible to set a timeout that if the end hasn't been reached to make some sort of alert that it failed - but possibly only for a debug mode.

@Deathamns

There is also a possible path where browser here is null

That's okay, I talked about only the factory.

Without it, once cleanup fails, the addon will never work properly again until Firefox is restarted

I'm not sure if it even should work if cleanup fails. Currently the whole background is held back from garbage collection because some references couldn't be removed.
If you add these kind of workarounds just to make it work, a previous version of the background page will still be hanging there, and it may not be that easy to notice it.

@AlexVallat
Collaborator

I'm not sure if it even should work if cleanup fails.

In that case it should report failure to startup so that the addon system informs the user they have to restart to enable it. The current behaviour of partial broken loading can't be right, though...

@Deathamns Deathamns merged commit c9f6a31 into chrisaljoudi:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 17, 2015
  1. @AlexVallat
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 3 deletions.
  1. +17 −3 platform/firefox/vapi-background.js
View
20 platform/firefox/vapi-background.js
@@ -371,6 +371,9 @@ var getTabBrowser = function(win) {
/******************************************************************************/
var getBrowserForTab = function(tab) {
+ if ( !tab ) {
+ return null;
+ }
return vAPI.fennec && tab.browser || tab.linkedBrowser || null;
};
@@ -457,6 +460,9 @@ vAPI.tabs.stackId = 1;
/******************************************************************************/
vAPI.tabs.getTabId = function(target) {
+ if ( !target ) {
+ return vAPI.noTabId;
+ }
if ( vAPI.fennec ) {
if ( target.browser ) {
// target is a tab
@@ -1010,6 +1016,15 @@ var httpObserver = {
Services.obs.addObserver(this, 'http-on-opening-request', true);
Services.obs.addObserver(this, 'http-on-examine-response', true);
+ // Guard against stale instances not having been unregistered
+ if ( this.componentRegistrar.isCIDRegistered(this.classID) ) {
+ try {
+ this.componentRegistrar.unregisterFactory(this.classID, Components.manager.getClassObject(this.classID, Ci.nsIFactory))
+ } catch (ex) {
+ console.error('µBlock> httpObserver > unable to unregister stale instance: ', ex);
+ }
+ }
+
this.componentRegistrar.registerFactory(
this.classID,
this.classDescription,
@@ -1813,10 +1828,9 @@ var optionsObserver = {
cleanupTasks.push(this.unregister.bind(this));
var browser = getBrowserForTab(vAPI.tabs.get(null));
- if ( browser.currentURI.spec !== 'about:addons' ) {
- return;
+ if ( browser && browser.currentURI && browser.currentURI.spec === 'about:addons' ) {
+ this.observe(browser.contentDocument, 'addon-enabled', this.addonId);
}
- this.observe(browser.contentDocument, 'addon-enabled', this.addonId);
},
unregister: function() {
Something went wrong with that request. Please try again.