question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

intermittent callback/channel issues in Safari 16

See original GitHub issue

I apologize upfront for the somewhat low quality of this bug report. It is a very hard bug to reproduce outside of our particular app (which is a big, heavy, app). And, even then, it’s non-deterministic, so a reduced repro isn’t going to be of much value. The bug isn’t in comlink, but I think there is a potential mitigation within comlink. Also, having this issue documented may help others.

On Safari 16.0, the basic callback pattern described here will sometimes silently stop working.

https://github.com/GoogleChromeLabs/comlink/tree/main/docs/examples/02-callback-example

Meaning, the callback may work for awhile, but at some point the callback function stops being called on the Main thread. This happens for callbacks with and without parameters passed in. Once it stops working, it never starts working again.

I traced into comlink and found that the postMessage from the Worker is successfully executed, but the addEventListener('message', ...) associated with the MessageChannel callback port is never invoked on the Main thread. There’s no messageerror callback on main, either.

I believe what’s happening is that Safari is inappropriately garbage collecting the MessageChannel under certain conditions. Things like memory pressure appear to play a role. Retaining the Endpoint created by the proxyTransferHandler and subscribed to in expose by pushing it into a module scoped data structure thus far appears to completely mitigate the problem for us.

It looks like Safari has had some issue in this space reported before: https://bugs.webkit.org/show_bug.cgi?id=193184 https://bugs.webkit.org/show_bug.cgi?id=184502

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dmarinicommented, Nov 3, 2022

@twmillett we are having the exact same issue in our application and I’d like to understand more about the mitigation that you have employed. We ended up using a straight postMessage/onMessage communication pattern to replace our callbacks that stopped working. We suspected we needed to strengthen the referential integrity of something but failed to identify the right object to operate with (tried the callback and the proxy itself).

Is the workaround you used to replace the comlink internal proxyTransferHandler in the transferhandlers collection with one that can store the “port1” reference created by MessageChannel()? Thanks in advance for any advice you can give.

0reactions
dmarinicommented, Nov 3, 2022

@twmillett this is great thank you, I’ll look into this if our current fix candidate continues to demonstrate the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

intermittent callback/channel issues in Safari 16 - IssueHint
Issue Title Created Date Comment Count Updated Date Keycloak unable to bind to directory 12 2021‑12‑21 2022‑10‑12 Upgrade to eCharts v5 5 2021‑01‑26 2022‑10‑08 Move important...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Fixed an issue where browser.tabs sometimes returned an incorrect URL for ... Many of the new Safari 16 features are now available in...
Read more >
Issues · GoogleChromeLabs/comlink - GitHub
intermittent callback /channel issues in Safari 16. #600 opened on Oct 26 by twmillett · 5. proxy causes test errors in Deno. #598...
Read more >
Fix list for IBM WebSphere Application Server V8.5
16. Fix Pack 8.5.5.14. 20 August 2018. 187. 11. Fix Pack 8.5.5.13 ... PI86097, Intermittent issues with APC promptly responding to lazy start...
Read more >
1006786 - Harassment and signal squelchening Description
For example when I open Safari I get Yahoo instead even though my default is ... ticket with me via email (5/24/16) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found