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

Many async commands causing seg fault using tauri 1.5.0 #8207

Closed
jimmieW opened this issue Nov 10, 2023 · 3 comments
Closed

Many async commands causing seg fault using tauri 1.5.0 #8207

jimmieW opened this issue Nov 10, 2023 · 3 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@jimmieW
Copy link

jimmieW commented Nov 10, 2023

Describe the bug

In our application we make use of tauris async commands (https://tauri.app/v1/guides/features/command/#async-commands).

This works well most of the time, but if we push the rate in which we create these commands our application crashes.

Reproduction

This can easily be reproduced by:

  1. Check out the tauri dev branch with the tauri-v1.5.0 tag.
  2. Change the following in the index.html found in the commands example: https://github.com/tauri-apps/tauri/blob/tauri-v1.5.0/examples/commands/.
      function runCommand(commandName, args, optional) {
	  for (let i = 0; i < 10000; i++) { // CHANGE A
              const id = optional ? '#response-optional' : '#response'
              const result = document.querySelector(id)
              window.__TAURI__
		  .invoke(commandName, args)
		  .then((response) => {
		      result.innerText = `Ok(${response})`
		  })
		  .catch((error) => {
		      result.innerText = `Err(${error})`
		  })
	  } // CHANGE B
      }
  1. Start the example application: cargo run --example commands
  2. Click the "Run async simple command" button (potentially repeat a few times) -> Crash.

Expected behavior

Should not crash.

Platform and versions

Environment
  › OS: Windows 10.0.22621 X64
  › Webview2: 119.0.2151.44
  › MSVC:
      - Visual Studio Professional 2019
      - Visual Studio Build Tools 2022
  › Node.js: 16.15.1
  › npm: 8.11.0
  › pnpm: Not installed!
  › yarn: 1.22.19
  › rustup: 1.26.0
  › rustc: 1.71.1
  › cargo: 1.71.1
  › Rust toolchain: stable-x86_64-pc-windows-msvc

Packages
  › @tauri-apps/cli [NPM]: 1.2.3
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: 1.4.1,
  › tauri-build [RUST]: 1.4.0,
  › tao [RUST]: 0.16.2,
  › wry [RUST]: 0.24.4,

App
  › build-type: bundle
  › CSP: font-src https://fonts.gstatic.com; default-src 'self' customprotocol: asset:; img-src 'self' asset: https://asset.localhost blob: data:; style-src 'unsafe-inline' 'self' https://fonts.googleapis.com
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: Svelte
  › bundler: Vite

App directory structure
  ├─ dist
  ├─ isolation-dist
  ├─ public
  ├─ src
  └─ src-tauri

Stack trace

For instance:
error: process didn't exit successfully: `C:\dev\tauri_debug\tauri\target\debug\examples\commands.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

Additional context

I noticed that if I run the same scenario on the current dev branch (commit: e9aa727) I get an assertion failure in the wry crate:

thread 'tokio-runtime-worker' panicked at 'PostMessage failed ; is the messages queue full?', C:\Users\jimmi.cargo\registry\src\index.crates.io-6f17d22bba15001f\wry-0.34.2\src\webview\webview2\mod.rs:1171:3

.cargo/registry/src/index.crates.io-6f17d22bba15001f/wry-0.34.2/src/webview/webview2/mod.rs

unsafe fn dispatch_handler<F>(hwnd: isize, function: F)
where
  F: FnMut() + 'static,
{
  // We double-box because the first box is a fat pointer.
  let boxed = Box::new(function) as Box<dyn FnMut()>;
  let boxed2: Box<Box<dyn FnMut()>> = Box::new(boxed);

  let raw = Box::into_raw(boxed2);

  let res = PostMessageW(HWND(hwnd), *EXEC_MSG_ID, WPARAM(raw as _), LPARAM(0));
  assert!(
    res.is_ok(),
    "PostMessage failed ; is the messages queue full?"
  );

I am more interested in a fix/workaround for the 1.5.0 version. I just added this since it might be a clue.

@jimmieW jimmieW added status: needs triage This issue needs to triage, applied to new issues type: bug labels Nov 10, 2023
@mrjackwills
Copy link
Contributor

I have also updated Tauri from 1.4 to 1.5 (obliqoro) and an now infrequently getting an illegal operation error. Is this something that could be related, and if so, what's the best way to debug this to find the cause?

I rebuilt the application with a revert to Tauri 1.4, and the error no longer occurs.

Screenshot 2023-12-01 160520

@0rvar
Copy link
Contributor

0rvar commented Dec 8, 2023

Might be related to #8177

@FabianLars
Copy link
Member

superseeded by #10546 i guess

@FabianLars FabianLars closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
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