Skip to content

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

Merged
lucasfernog merged 3 commits into
tauri-apps:devfrom
charrondev:fix/wkwebview-cookies-runloop
Mar 2, 2025
Merged

fix(macos): fix race condition in wkwebview implementation of cookie fetching#1486
lucasfernog merged 3 commits into
tauri-apps:devfrom
charrondev:fix/wkwebview-cookies-runloop

Conversation

@charrondev

@charrondev charrondev commented Feb 11, 2025

Copy link
Copy Markdown
Contributor

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
@github-actions

github-actions Bot commented Mar 2, 2025

Copy link
Copy Markdown
Contributor

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
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.

3 participants