Open Bug 1834683 Opened 3 years ago Updated 2 years ago

Manifest v3 event page may terminate immediately after computer awakens from 30+ second sleep in Windows 10.

Categories

(WebExtensions :: Untriaged, defect, P3)

Firefox 115
defect

Tracking

(Not tracked)

People

(Reporter: anonymous30901032, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

2.88 KB, application/x-zip-compressed
Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0

Steps to reproduce:

Attached is a Manifest v3 extension with an event page that increments a counter on its button badge by 5 every five seconds. The counter is initialized to 0 when the extension starts or restarts. The event page also performs a keep alive operation every five seconds. This prevents it from being suspended. If the computer is put to sleep and awakened after 30 seconds have passed, the counter may reset to 0, signifying the event page was restarted.

  1. Install the attached extension in about:debugging.
  2. Wait for around 30 seconds or so, allowing the counter to progress.
  3. Put the computer to sleep.
  4. Immediately awaken the computer. The counter will not have reset.
  5. Put the computer to sleep again.
  6. Wait 30 seconds or longer.
  7. Awaken the computer. The event page often restarts, setting the counter to 0. It also may not restart. If that is the case, repeat steps 5-7. It may take multiple attempts to reproduce the restart.

Expected results:

The event page should not restart when the computer awakens from a sleep that was longer than 30 seconds. This may only be a Windows or Windows 10 issue. When testing on Linux Mint, the event page did not restart and worked correctly.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

I’m not sure that I reproduced the issue as the counter does not reset after waking the pc from the 30+ seconds sleep.
However, what I noticed was that after waking from that 30+ seconds sleep, the counter does not progress anymore and the background script is stopped.
I repeated the process 8 to 10 times and that is what I got.

Tested on the latest Nightly (115.0a1/20230525234553) and Release (113.0.2/20230522134052) under Windows 10 x64.

Whiteboard: [addons-jira]

The severity field is not set for this bug.
:zombie, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(tomica)

There are two things in this bug:

  1. The extension is artificially trying to prevent the page from suspending by triggering (expensive) events. This mechanism is strongly discouraged, because storage changes are propagated to all processes (content scripts and extension pages). Moreover, there is no guarantee of this working. The extension should be designed to be resilient against being terminated. The keep-alive work-around here doesn't work against process crashes for example (e.g. out-of-memory crash on desktop, or just a plain process termination on Android).

  2. The event page is automatically suspended after 30 seconds of inactivity. When the laptop is suspended, that should not count towards this 30 seconds.

We should check whether issue 2 is happening, and if so fix that.

Blocks: 1587876
Severity: -- → S3
Flags: needinfo?(tomica)
Priority: -- → P3

After testing further, an event page will stop if its timer (in real time) exceeds 30 seconds after a computer wakes up from sleep. This matches with what happens when an event page that didn't sleep is running code at the exact moment its 30 second timer expires. It is terminated before all the code finishes running.

It looks like what caused the event page in the attached extension to restart was an expired setTimeout being run instantly after awakening. This made a storage.local.set call. The event page was then terminated and immediately restarted because it was listening to storage.local.onChanged. It probably comes down to chance between the termination happening first or the function from the setTimeout being evaluated.

Perhaps this issue needs to be closed and a different issue filed. Ideally, an event page should have its timer reset to 30 seconds when awakening from sleep mode.

It's not clear what you mean - your code has a timer, and technically the event page sleep is a timer. Could you clarify?

Given the following situation:

  1. Event page has activity
  2. X seconds elapsed
  3. Computer sleeps.
  4. Y seconds elapsed.
  5. Computer wakes.
  6. Z time elapsed.

My expectation is that the event page suspends if X + Z > 30 (i.e. time while sleeping doesn't count).
I can also imagine the implementation sleeping if X + Y + Z > 30 happens (i.e. time while sleeping counts). I would be interested in fixing this (point 2 of comment 4).

Yes, the time while sleeping counts. So if (X + Y + Z) > 30 when the computer awakens (Z === 0), the event page is immediately terminated.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Manifest v3 event page may restart after computer awakens from 30+ second sleep in Windows 10. → Manifest v3 event page may terminate immediately after computer awakens from 30+ second sleep in Windows 10.
Depends on: 1874406

We schedule background termination using a nsITimer, which uses TimeStamp::Now() as a time reference.

On Linux and macOS, this uses time excluding suspended time, but on Windows sleep time is included, as reported before at bug 1204823.

Depends on: 1204823
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: