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

[persisted-scope] Memory leak in tauri-plugin-persisted-scope #274

Closed
mooijtech opened this issue Jan 15, 2023 · 6 comments · Fixed by #328 or #341
Closed

[persisted-scope] Memory leak in tauri-plugin-persisted-scope #274

mooijtech opened this issue Jan 15, 2023 · 6 comments · Fixed by #328 or #341

Comments

@mooijtech
Copy link

Describe the bug

tauri-plugin-persisted-scope v0.1.0 causes a memory leak until OOM.
Not using the plugin fixes the OOM.

Reproduction

tauri::Builder::default()
    .plugin(tauri_plugin_persisted_scope::init())
    .run(tauri::generate_context!())
    .expect("error while running tauri application")

Expected behavior

No memory leak :)

Platform and versions

$ tauri info

Environment
  › OS: Arch Linux Unknown X64
  › Node.js: 16.13.2
  › npm: 9.3.0
  › pnpm: 6.11.0
  › yarn: 3.3.1
  › rustup: 1.25.1
  › rustc: 1.63.0
  › cargo: 1.63.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
WARNING: no lock files found, defaulting to npm
  › @tauri-apps/cli [NPM]: 1.2.2
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: 1.2.3,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

Stack trace

No response

Additional context

No response

@mooijtech
Copy link
Author

I checked the contents of the .persisted-scope file and it's a 54MB file containing endless [[][]][]][[][[][]][[][[][]][[][]][]][[][[][]][[][]][]][[][]][]][[][[][]][[][[][]][[][]][]]...

Something not validated correctly in the plugin?

@FabianLars
Copy link
Member

You're the second one reporting this exact behavior (the other one's file was a bit above 100MB). In that case it didn't occur after a code refactor anymore so we weren't able to debug it.

If you rename the file, does it get recreated with the same issue? If so, it would be much appreciated if you could share your project so that we can debug the root cause 🙏

@mooijtech
Copy link
Author

mooijtech commented Jan 15, 2023

The file gets recreated fine but I can't reproduce the issue.
I tried in development and also compiled.
At least the cause of the memory issue is known, was taking up ~5GB for me :)

The file browser (open) allows selecting outside the file extension filter if at least one selected file is within the filter. Edit: As in you can select a directory as well.
Guess that's a WebView2 problem though.

It would also be nice to be able to select both files (with filter) and directories in the same dialog.

Drag and drop is also not limited to a filter for the persisted scope.

Thank you for your support, I appreciate it 🙏🏻

@mooijtech
Copy link
Author

The bug came back again, so still present

@FabianLars
Copy link
Member

Do you have any pointers what could've caused this? Like what did you do that extended the scope. Or maybe some code?

We weren't able to reproduce it ourselves yet and only 2 people reported this so far (the other guy wasn't able to repro it since then either)

@mooijtech
Copy link
Author

Not sure if it's an issue in bincode, seems like they are close to v2.0.0
When I have time I can get tauri-plugin-persisted-scope running locally with some debug statements to check what it's writing.

The scope gets added by the following code, using @tauri-apps/api/dialog (nothing special):

const onBrowse = () => {
    open({
        title: "Example",
        directory: false,
        multiple: true,
        filters: [{
            name: "Supported",
            extensions: ["pst"],
        }],
    }).then((selectedFiles) => {
       // Update state
    })
}

@FabianLars FabianLars transferred this issue from tauri-apps/tauri Mar 9, 2023
@FabianLars FabianLars changed the title [bug] Memory leak in tauri-plugin-persisted-scope [persisted-scope] Memory leak in tauri-plugin-persisted-scope Mar 9, 2023
FabianLars added a commit that referenced this issue Apr 26, 2023
* fix(persisted-scope): Unescape paths before saving to disk.

* fix cfg flags

* dedupe code

* unescape when reading to try to fix existing files

* add more patterns. only fix pattern on app start. don't check if pattern is allowed already.

* remove dbg log

* typo

* remove unused imports

* clippy

* fix compilation with asset-protocol feature flag enabled

* update patterns

* manually re-save state once

* add changefile

* remove dbg print
This was referenced Apr 26, 2023
OrIOg pushed a commit to OrIOg/plugins-workspace that referenced this issue Jun 25, 2023
 (tauri-apps#328)

* fix(persisted-scope): Unescape paths before saving to disk.

* fix cfg flags

* dedupe code

* unescape when reading to try to fix existing files

* add more patterns. only fix pattern on app start. don't check if pattern is allowed already.

* remove dbg log

* typo

* remove unused imports

* clippy

* fix compilation with asset-protocol feature flag enabled

* update patterns

* manually re-save state once

* add changefile

* remove dbg print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants