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

[bug] Deadlock when sending events with tracing enabled (v2 beta) #9453

Open
dceddia opened this issue Apr 12, 2024 · 3 comments
Open

[bug] Deadlock when sending events with tracing enabled (v2 beta) #9453

dceddia opened this issue Apr 12, 2024 · 3 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@dceddia
Copy link
Contributor

dceddia commented Apr 12, 2024

Describe the bug

[ moving this here from Discord ]

I'm getting a deadlock when I try to resize the window (or re-focus it, or any other action that sends a window event from the main thread to itself).

See the video for some more details, but this is the gist:

It seems like the deadlock is caused when one of my (not main) threads runs a window.emit('whatever', ...), which acquires a lock on the webview and holds it until the script has been run (I think - not 100% sure on what it waits for). Then when I resize the window, that tries to acquire a lock on the webview too, which is already locked by the emitted event. Then it just hangs forever because it can't get the lock until the main thread runs the emitted JS thing, which will never happen because it's paused waiting for the lock 🙃 That's my theory anyway.

I noticed it seemed to start happening when I added the tauri-devtools plugin. With Fabian's suggestion in Discord, I was able to create a minimal reproduction with just the tauri tracing feature enabled. I can't get it to happen when tracing is not enabled.

Fabian thought this might be related: #9429

tauri-v2-deadlock.mp4

Reproduction

https://github.com/dceddia/tauri-tracing-freeze

Expected behavior

Ideally no deadlock 😄

Full tauri info output

This is from the minimal repro:

Projects/tauri-tracing-freeze % pnpm tauri info

> tauri-tracing-freeze@0.0.0 tauri /Users/dceddia/Projects/tauri-tracing-freeze
> tauri "info"


[✔] Environment
    - OS: Mac OS 14.2.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.77.1 (7cf61ebde 2024-03-27)
    ✔ cargo: 1.77.1 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.8.0
    - pnpm: 8.11.0
    - yarn: 1.22.21
    - npm: 10.1.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.14
    - tauri-build [RUST]: 2.0.0-beta.11
    - wry [RUST]: 0.39.0
    - tao [RUST]: 0.27.0
    - tauri-cli [RUST]: 1.4.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.7
    - @tauri-apps/cli [NPM]: 2.0.0-beta.12

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

Stack trace

There's no crash, but check out the video for some relevant stack traces while execution was paused.

Additional context

No response

@dceddia dceddia added status: needs triage This issue needs to triage, applied to new issues type: bug labels Apr 12, 2024
@Ovenoboyo
Copy link

Ovenoboyo commented Aug 10, 2024

Minimal reproduction: https://github.com/Ovenoboyo/tauri-tracing-deadlock

^ The code spawns a thread which loops and keeps emitting events to the webview
The webview on receiving the event calls an invoke command

With the tracing feature active, the main thread is stuck on acquiring the lock since the thread with tracing is still waiting for a message from the webview.

@guseggert
Copy link

I'm experiencing something very similar when resizing while events are being emitted at a high frequency (around once every 10 ms), the app deadlocks. I'm able to work around it by using a channel instead.

Image

@DeTeam
Copy link
Contributor

DeTeam commented Mar 4, 2025

I have similar symptoms just from emitting on app within a non-async command. Running an older version of Tauri, though. Don't have tracing enabled explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants