-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(linux): reuse WebContext to prevent WebKitNetworkProcess leak #14628
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
base: dev
Are you sure you want to change the base?
Conversation
Package Changes Through c5a327aThere are 3 changes which include tauri-utils with patch, tauri-build with patch, tauri-cli with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
I feel like fixing this would be the more appropriate but i wouldn't mind your approach that much if that's not possible, assuming that it's properly killed once the app actually exits. |
|
And perhaps it should also be investigated a bit upstream: tauri-apps/wry#590 though it may very well be possible that we just have to document that downstream (in this case tauri) has to handle this. |
|
Hey @FabianLars
for your concern of the tray applications I have added docs in the code that makes the behavior clear that the process will still terminate when the app exits since on Linux that's the expected behavior whenever an app closes!
Upon investigating the issue you mentioned I feel like the patch belongs to this repo only! |
i was thinking that this would be kinda wasteful to keep processes open that aren't used. Like the rust process is like 5mb and we keep a 25mb process around for perhaps no reason? doesn't sound in line with tauri's philosophy to me. |
I understand your concerns @FabianLars but my idea or approach is that if we keep the process alive and the window closes there would be no further needs to restart that process again! which could speed up things! and as far as I know not many people would care about extra ~25Mb being used in their RAM as long as it's useful + gives a advantage! And if that doesn't sound good we can add a configurable option so the users can go to the tauri-conf.json and set true if they want the process alive or killed after the window is closed. What do you think? |
More efficient ram usage is one of the major reasons people switch to tauri and there's really not much of an advantage here as re-starting the network process is faster than re-starting the other processes so this should be done before you even notice it.
For that we first have to fix the issue that prevents it from being killed :D I'd be okay with merging your change if it means we will investigate the actual issue and switch to the fix then. == We'd take your PR as a temporary workaround to get rid of the tens of zombie processes for now. |
|
Thanks for the feedback @FabianLars I get it that keeping WebKitNetworkProcess alive is a minor memory overhead and that restarting it would be fast enough in most cases. So if you are fine with it... you can happily merge my PR as a temp work around and I will work on fixing this bug and adding the configurable option if you are fine with it :) |
|
i'd very much appreciate it if you could look into the root issue here and fix it! Don't bother with a config though, that really isn't worth it, we don't keep any webview processes running on any platform so there's no reason to allow devs to do that for this single process :) |
|
Thanks! @FabianLars I will investigate the root issue here and work on fixing this ASAP :D |
|
Umm... hey! @FabianLars I did a bit of thorough investigation, and the results are quite interesting! WebKit itself is responsible, not Tauri :O The root cause is in WebKit's architecture:
What to do? The proper fix would be in WebKit upstream to either:
So seems like my work-around works xD now my confusion is that if this is a WebKit issue on linux itself... I don't think there's much we can do, Maybe go and fix WebKit? xD IDK if you already knew this or not but yeah this is all I was able to find really. |
|
This is so stupid but it's also such a webkit thing to do. Really makes no sense to me that it behaves that way with no way to opt-out Thanks for the investigation nonetheless! |
|
Glad it helped! @FabianLars, anyways... curious about what to do next for this issue? |
|
hmm i guess nothing to do for you anymore. We need to test it ourselves now but i know that we're all insanely busy at work right now. Since i'm in the car with a hotspot for now maybe i can do it quickly now, can't actually work here anyway. |
|
ah and we need a changefile similar to https://github.com/tauri-apps/tauri/pull/14620/changes#diff-4d219b4237dee6e7ef1d053a6c0ea396331048f5fcc8eb105d4b9813ee9e5e6b (but |
crates/tauri-runtime-wry/src/lib.rs
Outdated
| // On Linux/BSD, we keep the WebContext alive even when all windows are closed. | ||
| // This ensures only one WebKitNetworkProcess is spawned for the lifetime of the app. | ||
| // For tray-only or long-running apps, the process will still terminate when the application exits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // On Linux/BSD, we keep the WebContext alive even when all windows are closed. | |
| // This ensures only one WebKitNetworkProcess is spawned for the lifetime of the app. | |
| // For tray-only or long-running apps, the process will still terminate when the application exits. | |
| // https://github.com/tauri-apps/tauri/issues/14626 | |
| // Because WebKit does not close its network process even when no webviews are running, we need to ensure to re-use the existing process on Linux by keeping the WebContext alive for the lifetime of the app. | |
| // WebKit on macOS handles this itself. |
formatting will be off but whatever
|
seems to work well in my quick test, thanks |
Thanks @FabianLars I have applied your suggestion with a clear formatting... if there are other changes please let-me know I will apply them ASAP :) |
|
Thanks! I don't expect any changes but I'm away over the weekend (already am) so won't be able to merge until Monday earliest :) |
No problems! @FabianLars enjoy, take your time, and have fun! |
This PR fixes the issue where
WebKitNetworkProcessinstances are left running after closing Tauri windows on Linux.When a webview is destroyed on Linux, the
WebContextis removed from the context store if no other webviews reference it. When a new window is created later, a newWebContextis allocated, which spawns a newWebKitNetworkProcess. WebKit does not terminate these network processes when the context is dropped, leading to process accumulation.Solution applied in this PR:
Keep the
WebContextalive on Linux/BSD platforms even when all referencing webviews are closed. This allows the context to be reused by future webviews, ensuring only a singleWebKitNetworkProcessis spawned during the application's lifetime.Resolves
Issue: #14626