Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

charrondev
Copy link

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants