Closed Bug 906030 Opened 11 years ago Closed 11 years ago

Regression: Unable to start a Guest Session; menu item stuck on 'Exit Guest Session'

Categories

(Firefox for Android Graveyard :: General, defect)

26 Branch
ARM
Android
defect
Not set
normal

Tracking

(firefox25+ verified, firefox26 verified, fennec26+)

VERIFIED FIXED
Firefox 26
Tracking Status
firefox25 + verified
firefox26 --- verified
fennec 26+ ---

People

(Reporter: aaronmt, Assigned: wesj)

References

Details

(Keywords: regression, reproducible)

Attachments

(3 files, 2 obsolete files)

Open the menu, see 'Exit Guest Session'. Selecting that will restart Fennec with the same profile.

--
Nightly (08/16)
tracking-fennec: --- → ?
Interestingly I don't see this issue on my 4.2.2


On my 4.3 devices (Nexus 4, Galaxy SIV)

Startup:

I/GeckoThread(31177): RunGecko - args =  -profile /data/data/org.mozilla.fennec/files/mozilla/tz4pyxxg.guest

On entry 'Exit Guest Session' shown as the item name

W/GeckoProfile(31421): requested profile directory missing: /data/data/org.mozilla.fennec/files/guest

It restarts with the default profile

I/GeckoThread(31421): RunGecko - args =  -profile /data/data/org.mozilla.fennec/files/mozilla/tz4pyxxg.guest

On my HTC One 4.2.2

On entry it works as expected and the name of the item is shown correctly

I/GeckoThread(23330): RunGecko - args = --guest-mode -profile /data/data/org.mozilla.fennec/files/guest
Reproduced on the new Nexus 7 (2013) on fresh install (4.3) as well
Unable to reproduce on the Galaxy Note II (4.2)
Scratch that, I nuked an older install and re-installed cleanly and was able to reproduce. Having an older install prior to the mentioned bug seems to have things work out fine. New installations seem to be faulty.
Assignee: nobody → bnicholson
tracking-fennec: ? → 26+
Grr. Yeah, this exposed a separate bug. i.e. before we were creating the directory so creating a profile with

GeckoProfile(context, "guest", file);

would use the File passed in. Now, since that file doesn't exist, GeckoProfile creates it and happily adds it to profiles.ini for us at the same time.
Assignee: bnicholson → wjohnston
Attached patch PatchSplinter Review
This basically

1.) Assumes that getGuestProfile always returns something
2.) Is careful not to create a profile before locking it (I also added a similar check in unlock just to be consistent here)

I'm working on a larger refactor of this (and shilpan is deleting all of the profiles.ini code). In the mean time, I think this is a pretty simple fix.
Attachment #794275 - Flags: review?(bnicholson)
With this patch, users who've installed nightly since the switch will still be stuck in a "guest" profile forever. I can newsgroup post if we want, or we could ship some code to get them out if their profile name is "guest".
I found several issues looking through the guest profile code, so I'll try to fix them all here.

I found that maybeCleanupGuestProfile() isn't returning what we'd expect. In BrowserApp, we set mRestoreMode to RESTORE_NORMAL if maybeCleanupGuestProfile() is true, so that implies that the return value should be the current guest mode status. This patch fixes that.
Attachment #794283 - Flags: review?(wjohnston)
Oh great, looks like we've been working on the same bug! If only we hadn't just had that fire drill, I would have gotten mine up first.... Anyway, I'll just post the rest and we can decide which ones to take after that.

Here's the second part. getGuestProfile() was creating the profile if it didn't exist, so the guest profile was still getting set at every startup. This changes getGuestProfile() to only call get() if the profile actually exists already.
Attachment #794286 - Flags: review?(wjohnston)
Comment on attachment 794283 [details] [diff] [review]
Part 1: Fix return values for maybeCleanupGuestProfile

Review of attachment 794283 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/base/GeckoProfile.java
@@ +181,5 @@
> +    /**
> +     * Removes the guest profile if guest mode is no longer active.
> +     *
> +     * @param context Context for retrieving profile path
> +     * @return        Whether the user is still in guest mode

This isn't what I imagined this return was for. In my mind, since this method was a "maybe" method, the return told you whether or not it actually did what you asked. i.e. return true if we deleted a guest profile. Then browserApp would restore session if we were deleting the profile (i.e. coming out of guest mode).

With this patch, we'll restore session if the guest profile exists but isn't locked?
Attachment #794283 - Flags: review?(wjohnston)
There's a race condition removing the guest profile since it happens in the background thread. If getGuestProfile() is called any time before the background thread has finished, mInGuestMode will be set to true even though we're not actually in guest mode anymore.

This could be fixed by adding synchronization logic to make sure we don't try to call getGuestProfile() before a remove has finished, but that would add more overhead to every startup and wouldn't be a good idea. We could also maybe add some booleans and/or reorder the code to fix this, but I chose to just get rid of the background thread altogether. We'll only hit this code path to begin with when we're leaving guest mode (not that common), plus we already create the guest profile synchronously anyway.
Attachment #794290 - Flags: review?(wjohnston)
Final patch. This removes the exception catching in createGuestProfile(). In BrowserApp, we set the result to mProfile whether we succeed or not, so we'll crash either way. Catching generic exceptions here only makes things more difficult to debug since we'll get a NPE instead of the actual stack trace.
Attachment #794292 - Flags: review?(wjohnston)
Comment on attachment 794286 [details] [diff] [review]
Part 2: Don't always create the guest profile at startup

Review of attachment 794286 [details] [diff] [review]:
-----------------------------------------------------------------

I think I like this (although it conflicts with my patch).
Attachment #794286 - Flags: review?(wjohnston) → review+
Comment on attachment 794283 [details] [diff] [review]
Part 1: Fix return values for maybeCleanupGuestProfile

(In reply to Wesley Johnston (:wesj) from comment #11)
> Comment on attachment 794283 [details] [diff] [review]
> Part 1: Fix return values for maybeCleanupGuestProfile
> 
> With this patch, we'll restore session if the guest profile exists but isn't
> locked?

Oh right, I was thinking we wanted to restore the session if we're still in guest mode, but it's the other way around. Forget this patch!
Attachment #794283 - Attachment is obsolete: true
Comment on attachment 794292 [details] [diff] [review]
0004-Bug-906030-Part-4-Don-t-catch-exceptions-in-createGu.patch

We have null checks, so I think you can ignore this patch too.
Attachment #794292 - Attachment is obsolete: true
Attachment #794292 - Flags: review?(wjohnston)
Comment on attachment 794292 [details] [diff] [review]
0004-Bug-906030-Part-4-Don-t-catch-exceptions-in-createGu.patch

Review of attachment 794292 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/base/GeckoProfile.java
@@ -150,5 @@
> -            return profile;
> -        } catch (Exception ex) {
> -            Log.e(LOGTAG, "Error creating guest profile", ex);
> -        }
> -        return null;

Hmm.. returning null here won't actually cause a crash though. Most of the time, BrowserApp doesn't assign a GeckoProfile at this point, and life goes on fine.

So with this, rather than gracefully moving on using your normal profile, we'll crash. Maybe we'd be better to show a toast or notification saying "Can't create a guest session :(" to the user. Or an alert dialog?
Attachment #794292 - Attachment is obsolete: false
Comment on attachment 794290 [details] [diff] [review]
Part 3: Don't remove guest profile on background thread

Review of attachment 794290 [details] [diff] [review]:
-----------------------------------------------------------------

I think I'm fine with this too.
Comment on attachment 794290 [details] [diff] [review]
Part 3: Don't remove guest profile on background thread

Review of attachment 794290 [details] [diff] [review]:
-----------------------------------------------------------------

I think I'm fine with this too.
Attachment #794290 - Flags: review?(wjohnston) → review+
Attachment #794292 - Attachment is obsolete: true
Verified Fixed on Nightly (08.27)
Comment on attachment 794286 [details] [diff] [review]
Part 2: Don't always create the guest profile at startup

[Approval Request Comment]
Bug caused by (feature/regressing bug #): Bug 901903
User impact if declined: Stuck on guest mode
Testing completed (on m-c, etc.): Landed on mc last week.
Risk to taking this patch (and alternatives if risky): Low risk. Fixes a regression from 901903. Needed if we want to land that on aurora.
String or IDL/UUID changes made by this patch: None.
Attachment #794286 - Flags: approval-mozilla-aurora?
Comment on attachment 794290 [details] [diff] [review]
Part 3: Don't remove guest profile on background thread

[Approval Request Comment]
Bug caused by (feature/regressing bug #): Bug 901903
User impact if declined: Stuck on guest mode
Testing completed (on m-c, etc.): Landed on mc last week.
Risk to taking this patch (and alternatives if risky): Low risk. Fixes a regression from 901903. Needed if we want to land that on aurora.
String or IDL/UUID changes made by this patch: None.
Bug 901903 exposes this bug, and since bug 901903 is going to land on Aurora, this affects 25.
Attachment #794286 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Wes, before I look anymore at your patch, do we still want it considering the other patches here landed?
Flags: needinfo?(wjohnston)
Hmm.. Maybe? That patch makes the locking code a little smarter, but more complex, to avoid this problem. Its pretty simple, so I'd be happy to get your take on it. Low priority?

I'm hoping that once profiles.ini is dead we can look for a way to do this without the locking bits, but we'll still need to store the prev profile somewhere so that when you leave guest mode, we have some idea what to load (maybe in profiles.ini?). Anyway, separate bug...
Flags: needinfo?(wjohnston)
Comment on attachment 794275 [details] [diff] [review]
Patch

Review of attachment 794275 [details] [diff] [review]:
-----------------------------------------------------------------

I'm not sure why I took so long to review this...it's not as confusing as I thought when I first looked at it. LGTM as long as you make sure to keep the null check.

::: mobile/android/base/GeckoProfile.java
@@ -68,5 @@
>              }
>  
>              GeckoProfile guest = GeckoProfile.getGuestProfile(context);
> -            // if the guest profile exists and is locked, return it
> -            if (guest != null && guest.locked()) {

The other patches in this bug changed getGuestProfile() so that it can actually return null, so I think you'll need to keep the null check here.

@@ +233,5 @@
>          if (mLocked != LockState.UNDEFINED) {
>              return mLocked == LockState.LOCKED;
>          }
>  
> +        // Be careful not to create a dir just to see if its locked

This comment makes sense looking at it in the before/after context of this bug, but you might want to be more explicit about what you mean (e.g., "Don't use getDir() here because..."), so that it's clear what you're talking about for someone trying to follow the code.

@@ +264,5 @@
>          return false;
>      }
>  
>      public boolean unlock() {
> +        // Be careful not to create a dir if it doesn't exist yet

Same here with this comment.
Attachment #794275 - Flags: review?(bnicholson) → review+
Whiteboard: [leave open]
https://hg.mozilla.org/mozilla-central/rev/0b479df9a59a
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 26
Verified fixed on:
Build: Firefox for Android 25.0a2 (2013-09-16) and Firefox for Android 26.0a1 (2013-09-16)
Device: LG Nexus 4
OS: Android 4.2.2
Status: RESOLVED → VERIFIED
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: