Closed Bug 1748945 Opened 4 years ago Closed 4 years ago

`GeckoSession.mWindow` is not thread safe but is annotated that it can be accessed from multiple threads

Categories

(GeckoView :: General, defect, P1)

Unspecified
All
defect

Tracking

(firefox-esr91 wontfix, firefox98 wontfix, firefox99 wontfix, firefox100 fixed)

RESOLVED FIXED
100 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox98 --- wontfix
firefox99 --- wontfix
firefox100 --- fixed

People

(Reporter: mcomella, Assigned: agi)

Details

(Whiteboard: [geckoview:m98][geckoview:m99])

Attachments

(1 file)

GeckoSession.mWindow does not have synchronized access. GeckoSession.isOpen is annotated that it can be called from @AnyThread so GeckoSession.mWindow will need to be synchronized or otherwise changed to be thread safe.

The variable is initialized on the UI thread in GeckoSession.open and nulled again in GeckoSession.close or abandonWindow so the consequence of not fixing this is that background threads may read a stale value – either the initial null value or they'll get the Window after it's been closed.

Severity: -- → S3
Priority: -- → P2
Priority: P2 → P1
Whiteboard: [geckoview:m98]

I think the @AnyThread in there is a mistake, I don't think we can reliably tell a consumer if a session is open on a background thread. Even with synchronized access to mWindow code like this will always be broken on a background thread:

        if (!session.isOpen()) {
          session.open(sGeckoRuntime);
        }

because another thread could open the session between the isOpen() and the session.open statements.

We should just change isOpen to @UiThread and verify that all calls actually happen on the UI thread.

The fact that isOpen is @AnyThread seems to be a mistake, I don't think we can
reliably tell a consumer if a session is open on a background thread.

Even with synchronized access to mWindow code like this would always be broken
on a background thread:

if (!session.isOpen()) {
  session.open(sGeckoRuntime);
}

because another thread could open the session between the isOpen() and the
session.open statements.

This patch changes isOpen to @UiThread. I verified that all calls actually
happen on the UI thread, except for the calls in GeckoSessionSettings where we
are trying to handle the case where a session was closed and then we would
allow modifying read-only settings. I think in that case we should ask the
embedder to use a new SessionSettings instance instead of forcing all calls to
be @UiThread.

Assignee: nobody → agi
Status: NEW → ASSIGNED
Whiteboard: [geckoview:m98] → [geckoview:m98][geckoview:m99]
Flags: needinfo?(calu)
Flags: needinfo?(agi)
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
Flags: needinfo?(agi)
Flags: needinfo?(calu)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: