RESOLVED DUPLICATE of bug 244549 240062
Worker is terminated if it is unreachable from root even if it has handlers & document is active
https://bugs.webkit.org/show_bug.cgi?id=240062
Summary Worker is terminated if it is unreachable from root even if it has handlers &...
Takuo Kihira
Reported 2022-05-04 04:07:45 PDT
When running some WebWorkers (or single worker), sometimes suddenly workers stop without any messages or events. https://dynamic-wasm-6128yfdg3-tkihira.vercel.app/worker-stall.html I've made small reproducible example here. This URL runs 6 workers but on my Intel Mac & Safari 14, M1 Mac & Safari 15, and iOS 15.4 Mobile Safari some workers stopped suddenly and couldn't finish all workers. This seems a threading problem, so if you can't reproduce it please retry it again.
Attachments
Yusuke Suzuki
Comment 1 2022-05-05 20:21:47 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); ```
Yusuke Suzuki
Comment 2 2022-05-05 20:26:57 PDT
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?
Yusuke Suzuki
Comment 3 2022-05-05 20:28:38 PDT
At least, manually clicking GC button made all stopped. So probably Worker's DOM activity would be wrongly calculated and worker is collected.
Takuo Kihira
Comment 4 2022-05-05 21:10:39 PDT
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.
Radar WebKit Bug Importer
Comment 5 2022-05-11 04:08:14 PDT
Ahmad Saleem
Comment 6 2022-05-28 18:22:09 PDT
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.
Ahmad Saleem
Comment 7 2022-12-24 02:08:16 PST
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?
youenn fablet
Comment 8 2023-01-01 23:45:21 PST
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 ***
Note You need to log in before you can comment on or make changes to this bug.