Closed Bug 1865148 Opened 2 years ago Closed 1 year ago

CookieBannerChild cleanup timeout never executes on some sites

Categories

(Core :: Privacy: Anti-Tracking, defect, P3)

defect

Tracking

()

RESOLVED FIXED
134 Branch
Tracking Status
firefox134 --- fixed

People

(Reporter: emz, Assigned: majaharding)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

I've observed this issue while testing a broken rule on https://futurezone.de
The timeout gets scheduled here with a 5 second delay, but is never executed.
Never executing the cleanup callback means that we keep polling for cookie banners indefinitely.

We use Timer.sys.mjs for setTimeout. When I switched over to use this.contentWindow.setTimeout the callback was executed successfully. The bug might be in the Timer.sys.mjs implementation.

Depends on: 1865149

Lowering priority now that we have a fixup in place (Bug 1865149).

Priority: P1 → P2

Bug 1865149 seems to work well and I don't have time to look into this further currently.

Assignee: pbz → nobody
Status: ASSIGNED → NEW
Priority: P2 → P3

I found the cause of this bug.

When the cleanup() function inside #promiseObserve() gets called with the result of the banner search, it cancels the observerCleanUpTimer, which can then no longer clean up the Button observer. The rules for https://futurezone.de match a banner on the page but not a button, hence why the bug shows up there.

Because the "load" event causes the cleanup timer to restart, the bug doesn't occur if "load" happens after "Starting to detect the target button".

Using this.contentWindow?.setTimeout() seemed to help, because the code to cancel that timeout was still lazy.clearTimeout(). i.e. The cleanup() function couldn't cancel the timeout and cause the bug.

I have a patch for this which fixes the bug and avoids the timing issues, I'll upload it shortly.

When the cleanup() function inside #promiseObserve() gets called with the result of the banner search,
it cancels the observerCleanUpTimer, which can then no longer clean up the Button observer.

I fixed this, and also other potential async timing issues, by stopping the cleanup function from cancelling
the timeout, and having the timeout set a persistent "givenUp" flag instead of trying to directly cancel the
promiseObserver.

Assignee: nobody → majaharding
Status: NEW → ASSIGNED
Pushed by smolnar@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/47562b188068 Fix CookieBannerChild.sys.mjs killing its cleanup timout prematurely r=pbz

Previously, some tests were failing because the interval function was not immediately
cleaned up when didDestroy() was called, which kept some references around and prevented
objects from being garbage collected.

I solved this by recognising that there are two ways that a promiseObserve can exit without
success: when the timeout expires, and when the CookieBannerChild is destroyed. These need
to be handled differently, so I gave each case a different AbortController.

Pushed by smolnar@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0ce90d5b5b94 Fix CookieBannerChild.sys.mjs killing its cleanup timout prematurely r=pbz https://hg.mozilla.org/integration/autoland/rev/f566974ded62 Use AbortControllers for destroying and timing out r=pbz
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 134 Branch
Flags: needinfo?(majaharding)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: