Summary: | Worker is terminated if it is unreachable from root even if it has handlers & document is active | ||
---|---|---|---|
Product: | WebKit | Reporter: | Takuo Kihira <takuo.kihira> |
Component: | WebCore JavaScript | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Normal | CC: | achristensen, ahmad.saleem792, cdumez, webkit-bug-importer, youennf, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 15 | ||
Hardware: | All | ||
OS: | All |
Description
Takuo Kihira
2022-05-04 04:07:45 PDT
I think Worker's DOM activity is not accounted as active when you missed a reference to workers. I think terminating that kind of workers are fine since we have no way to observe that, but SharedArrayBuffer adds a way to observe this termination side-effect. You can workaround by adding workers reachable from the GC root. ``` globalThis.workers = []; ... globalThis.workers.push(worker); ``` But maybe, I'm wrong, as worker has onmessage handler. But it seems that workers are terminated. @Chris, do you know when workers are terminated? At least, manually clicking GC button made all stopped. So probably Worker's DOM activity would be wrongly calculated and worker is collected. Thank you Yusuke, your workaround works on my environments well. By the way, maybe the ArrayBuffer is not SharedArrayBuffer because I create it with ``` const memory = new WebAssembly.Memory({ initial: 1 }); ``` and I don't specify `shared: true` option so I guess it could be a normal ArrayBuffer. I tried to reproduce this on Safari TP 146 and it seems to finish workers more reliably as compared to Stable Safari 15.4 but it is still intermittent (at least on first few tries but later finishing always) on some workers as they do get stuck. Safari Technology Preview 160 is reliably able to close all thread, I tried it even with 80 threads. Can someone else confirm that it is not an issue anymore? Duping to https://bugs.webkit.org/show_bug.cgi?id=244549 which was fixed a while ago. @Takuo, please reopen if this is still reproducible in latest STP. *** This bug has been marked as a duplicate of bug 244549 *** |