Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(macos): fix race condition in wkwebview implementation of cookie fetching #1486

Merged

Conversation

charrondev
Copy link
Contributor

@charrondev charrondev commented Feb 11, 2025

As I was implementing tauri-apps/tauri#12665 I noticed a completed hang of the application if cookies_for_url() was called multiple times in quick succession.

I'm no expect in rust or objc but my understanding of the code here is as follows:

  • WKHTTPCookieStore.getAllCookies() takes a callback to receive the cookies.
  • The interface we expose for fetching cookies is synchronous, so we need to loop and block for some period of time until we receive our results.
  • Looping purely in rust won't actually do the work properly, since the objc runloop (running on another thread? (potentially?) needs to be told to progress.
  • runUntilDate() didn't necessarily block until that date on the rust site of this operation.

In order to fix this I had to do a few things. Notably I had to do all of these things for the issue to go away consistently.

  • Replace runUntilDate() with acceptInputForMode_beforeDate().
  • Add some waiting in rust with by using recv_timeout() instead of try_recv

Now I'm sure there's something nasty under the hood causing this to happen, but I'm not really knowledgable enough to dive any deeper myself. I will say these changes fix the issue I was running into at the cost of an extra ms on my end.

@charrondev charrondev force-pushed the fix/wkwebview-cookies-runloop branch from 6e8440b to f02276d Compare February 11, 2025 08:45
Copy link
Contributor

github-actions bot commented Mar 2, 2025

Package Changes Through 4037f7e

There are 1 changes which include wry with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
wry 0.50.1 0.50.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@lucasfernog lucasfernog merged commit 5120a5c into tauri-apps:dev Mar 2, 2025
12 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants