Open Bug 1451381 Opened 6 years ago Updated 2 years ago

Worker event listeners can leak owning window

Categories

(Core :: DOM: Workers, enhancement, P2)

enhancement

Tracking

()

People

(Reporter: bkelly, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [MemShrink:P2], DWS_NEXT)

Attachments

(2 files)

In bug 1450358 I am adding some new runtime leak checking.  The Worker API appears to fail this test.
This test needs the infrastructure patches from bug 1450358 to work.  Currently the Worker API fails all three leak cases.

Andrea, can you take a look at what is going on?
Flags: needinfo?(amarchesini)
Whiteboard: [MemShrink]
Whiteboard: [MemShrink] → [MemShrink:P1]
I tried writing a simple DisconnectFromOwner() that did Terminate(), but that doesn't fix the leak here.
Attached patch patchSplinter Review
Here a patch but I don't think we should land the test because it will be probably intermittent: the releasing of the window happens when the worker ends its shutdown steps. This could take more than a couple of ForceGC() calls.
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Attachment #8969341 - Flags: review?(bkelly)
Priority: -- → P2
Comment on attachment 8969341 [details] [diff] [review]
patch

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

Shouldn't we call Terminate() from DisconnectFromOwner()?  Otherwise the worker thread will run between the window being closed and CC running.

Also, if you don't like the test using event_leak_utils.js, can you write another test like it that waits for the worker to shutdown?
Attachment #8969341 - Flags: review?(bkelly) → review+
(In reply to Ben Kelly [:bkelly] from comment #4)
> Also, if you don't like the test using event_leak_utils.js, can you write
> another test like it that waits for the worker to shutdown?

For example, you could have a test where the worker spins periodically calling BroadcastChannel.postmessage().  Then the test could listen for when the broadcast messages stop before triggering GC.
Ok... this is going to be interesting: the current worker code doesn't ends the event-loop when all the 'blocking' holders are released, but when _all_ the holders are released. The difference between blocking and non-blocking holders is only related to the busy-count value and when the worker is GCed/CCed. My patch fixes this but, it introduces an important issue with MozPromise.

Take a look at: https://searchfox.org/mozilla-central/source/xpcom/threads/MozPromise.h#461-466
Here, there is not a check of the return value of ::Dispatch(). But we should have a check, because, MozPromise doesn't use any WorkerHolder internally and the worker could be already shutting down when ::Dispatch() is called. The issue is easily reproducible with DOM Cache + workers, because DOM Cache is the only API using MozPromise exposed to workers (for now).

I'm still debugging this issue. I'll propose a solution soon.
As we discussed in IRC, the patches in bug 1456466 may help.  Specifically P5, P6, and P8.
Depends on: 1457157
Blocks: 1458940
Andrea, now that bug 1457157 is fixed, can this move forward?
Flags: needinfo?(amarchesini)
Yes. I did some tests today. The leak is gone, but not immediately how the test wants. I'll rewrite it tomorrow using a ping/pong with BroadcastChannel or... with a timer.
Flags: needinfo?(amarchesini)
Hey Andrea, what else has to happen for this bug to land?
Flags: needinfo?(amarchesini)
Pushed to try to see the state of these 2 patches. Keeping the NI.
Flags: needinfo?(amarchesini)
Andrew, do you know who can pick this back up again?
Flags: needinfo?(bugmail)
Putting this in the DWS_NEXT queue to be picked up.
Assignee: amarchesini → nobody
Flags: needinfo?(bugmail)
Whiteboard: [MemShrink:P1] → [MemShrink:P1], DWS_NEXT

Is DWS_NEXT still a thing?

Flags: needinfo?(bugmail)
Whiteboard: [MemShrink:P1], DWS_NEXT → [MemShrink:P2], DWS_NEXT

Yes, although this bug also benefits from being a P2.

Note for when we pick this up:

  • Bug 1522246 potentially fixed the delay comment 9 was talking about.
  • I could swear I saw some bug traffic go by recently about edge-cases relating to what/when DOMEventTargetHelper tries to help us drop things.
Flags: needinfo?(bugmail)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: