tauri-apps/tauri

[bug] Tauri application crashes after running for a while in Windows

muwoo opened this issue · 14 comments

muwoo commented

Describe the bug

My application will crash after running for a period of time on some Windows computers. I tried to obtain the crash information through the Rust Panic log:

pub fn setup_panic_handler() {
  use std::backtrace;
  use std::io::Write;
  std::panic::set_hook(Box::new(|info| {
    let backtrace = backtrace::Backtrace::force_capture();
    println!("panic occurred: {:?}", info);
    let _ = std::fs::File::create("mcs_platform_latest_panic.log")
      .and_then(|mut f| f.write_all(format!("{:?}\n{:#?}", info, backtrace).as_bytes()));
    std::process::exit(1);
  }));
}

But found that there was no output 😭.

The application crashes directly, I don’t know whether it is due to Rust Panic or a front-end memory leak. How do I troubleshoot and locate this situation?

This problem prevents us from promoting our application. We are very much looking forward to the official reply. If you have any suggestions or help, that would be great!

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment                           
    - OS: Windows 10.0.19045 X64          
    ✔ WebView2: 129.0.2792.52             
    ✔ MSVC: Visual Studio ���ɹ��� 2022    
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.11.1
    - pnpm: 7.33.7
    - yarn: 1.22.22
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 1.7.1
    - tauri-build [RUST]: 1.5.2
    - wry [RUST]: 0.24.10
    - tao [RUST]: 0.16.9
    - @tauri-apps/api [NPM]: 1.5.7-beta.3
    - @tauri-apps/cli [NPM]: 1.6.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

Check the windows Event viewer, it may contain some information. Otherwise, make a reproduction and I will take a look

muwoo commented

@amrbashir
Sorry for the long wait. I have been searching for logs from my users for the past few days, and finally, I have received the error message from the event viewer

Incorrect application name: Dewu Merchant Customer Service 3.0.exe, version: 3.0.21.0, timestamp: 0x66f6a7fd
Error module name: ntdll.dll, version: 192.168.19041.4842, timestamp: 0xaabba71d
Exception code: 0xc0000005
Error offset: 0x000446a6
Error process ID: 0x5b3c
Wrong application startup time: 0x01db1159f4a7624d
Wrong application path: C: \ Users \ Administrator \ AppData \ Local \ Customer Service 3.0 \ Customer Service 3.0.exe
Error module path: C: \ Windows \ SYS32 \ ntdll.dll
Report ID: 08a1c3d8-e7B5-43A4-9e95-e62721f65948
Wrong package full name:
Error package relative to application ID:

The detailed information is as follows:

Customer Service 3.0
 [3.0.21.0](http://3.0.21.0/)
 66f6a7fd
 ntdll.dll
 10.0.19041.4842
 aabba71d
 c0000374
 000e6e13
 3040
 01db15f06bbba29c
 C:\Users\Administrator\AppData\Local\Customer Service 3.0\Customer Service 3.0.exe
 C:\Windows\SYSTEM32\ntdll.dll
 edca85df-dfea-4a29-a89b-3804b6fbdf71

I have no clue about these mistakes, and I really look forward to your help, Thanks alot !

muwoo commented

This is an error message from another user
img_v3_02fb_758167fe-5d23-4f9b-8baa-0fd4169eae4g

I don't see anything useful tbh, I'd try replicating with a minimal example, otherwise I can't investigate further

muwoo commented

@amrbashir I seem to have found a problem, which may be the reason why I frequently call appWindow.setAlwaysOnTop(true);.
I used Tauri window to make a message notification window in my chat application. Every time this message pop-up window receives a new message, it calls appWindow.setAlwaysOnTop(true);. If there are few messages, it does not matter, but as the volume of messages increased, it would crash.

muwoo commented

My code is like this:

const onNewMessage = () => {
  appWindow.setAlwaysOnTop(true);
  appWindow.show();
  // other code
}

. If there are few messages, it does not matter, but as the volume of messages increased, it would crash.

Sounds like maybe it crashes while sending the message, to that window, I'd try to optimize this part and see if it fixes your issue. Otherwise feel free to make a minimal repro and I will check it out.

muwoo commented

Okay, I will try to reproduce this problem with a clean project. When I reproduce it, I will provide a demo. Thanks alot!

muwoo commented

@amrbashir In vuejs, copy the following code and wait for a period of time (about 10 minutes) to reproduce it stably.

import {appWindow} from "@tauri-apps/api/window";
import {onMounted} from "vue";

onMounted(() => {
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(123123);
  }, 500);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(123123);
  }, 1000);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(123123);
  }, 200);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(123123);
  }, 200);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(123123);
  }, 200);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(2222);
  }, 100);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(2222);
  }, 100);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(2222);
  }, 100);
  setInterval(() => {
    appWindow.setAlwaysOnTop(true);
    console.log(2222);
  }, 50);
});
muwoo commented

I found that not only the setAlwaysOnTop function can cause crashes, but also calling requestUserAttention in batches for a long time when the window is not in the focused state. I am not sure whether show or hiden also have the same problem.

muwoo commented

show() and hide() should also have common problems. Here is my code, which will also crash:

onMounted(() => {
  setInterval(async () => {
    await appWindow.show();
    setTimeout(async () => {
      await appWindow.hide();
    }, 100)
  }, 100)
});

I couldn't reproduce the crash unfortunately. If the crash happens because of repetitive calls in short time, it maybe the same bug as #10546

muwoo commented

@amrbashir I tried catching the error via SetUnhandledExceptionFilter and found this error:

stack backtrace:
0 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    backtrace::backtrace::trace::he3a7a44c5988c3c3
 at unknown
1 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    backtrace::capture::Backtrace::new::h7f575fe994784047
 at unknown
2 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tauri_app::signal::sys::windows::handle::h5c72c48605b18fff
 at unknown
3 File C:\windows\System32\KERNELBASE.dll: 
    UnhandledExceptionFilter
 at unknown
4 File C:\windows\SYSTEM32\ntdll.dll: 
    memset
 at unknown
5 File C:\windows\SYSTEM32\ntdll.dll: 
    _C_specific_handler
 at unknown
6 File C:\windows\SYSTEM32\ntdll.dll: 
    _chkstk
 at unknown
7 File C:\windows\SYSTEM32\ntdll.dll: 
    RtlRaiseException
 at unknown
8 File C:\windows\SYSTEM32\ntdll.dll: 
    KiUserExceptionDispatcher
 at unknown
9 File C:\windows\SYSTEM32\ntdll.dll: 
    RtlSetUserValueHeap
 at unknown
10 File C:\windows\SYSTEM32\ntdll.dll: 
    RtlAllocateHeap
 at unknown
11 File C:\windows\SYSTEM32\ntdll.dll: 
    RtlAllocateHeap
 at unknown
12 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    <hashbrown::map::HashMap<K,V,S,A> as core::clone::Clone>::clone::h948c8cd035bbb8fb
 at unknown
13 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tauri::manager::WindowManager<R>::emit_filter::hd8fa96abacb4fa8a
 at unknown
14 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tauri::manager::on_window_event::hc9cbbf95be34a5b2
 at unknown
15 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tauri::window::Window<R>::on_window_event::{{closure}}::h0e505c65d6442d23
 at unknown
16 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tauri_runtime_wry::handle_event_loop::hd7adbf25640ce0f2
 at unknown
17 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::EventLoop<T>::run_return::{{closure}}::h7db322d92371fd62
 at unknown
18 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    std::panicking::try::h23e2bc9145391e3d
 at unknown
19 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::runner::EventLoopRunner<T>::catch_unwind::h078e3f6f79f3cde2
 at unknown
20 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::runner::EventLoopRunner<T>::register_window::hff174caaf0407fee
 at unknown
21 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::runner::EventLoopRunner<T>::send_event::ha999e6d45bab3359
 at unknown
22 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    std::panicking::try::h69545213fd817aac
 at unknown
23 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::runner::EventLoopRunner<T>::catch_unwind::hcafdc70dec2525be
 at unknown
24 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::thread_event_target_callback::h187ecd7ee3758c52
 at unknown
25 File C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f62e16\comctl32.dll: 
    DefSubclassProc
 at unknown
26 File C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f62e16\comctl32.dll: 
    DSA_Create
 at unknown
27 File C:\windows\System32\user32.dll: 
    CallWindowProcW
 at unknown
28 File C:\windows\System32\user32.dll: 
    DispatchMessageW
 at unknown
29 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    tao::platform_impl::platform::event_loop::EventLoop<T>::run::h464871dc8949d30c
 at unknown
30 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    <tauri_runtime_wry::Wry<T> as tauri_runtime::Runtime<T>>::run::h4f4eff3b34e712d7
 at unknown
31 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    state::container::Container<K>::with_map_ref::h4a9891d61590e022
 at unknown
32 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::hc4757481e639da93
 at unknown
33 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    std::sys_common::backtrace::__rust_begin_short_backtrace::h80fe5c9804cd5fba
 at unknown
34 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    std::rt::lang_start::{{closure}}::h17490383866d34d6
 at unknown
35 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    std::rt::lang_start_internal::closure$2
 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\rt.rs:148
    std::panicking::try::do_call
 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:552
    std::panicking::try
 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:516
    std::panic::catch_unwind
 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panic.rs:142
    std::rt::lang_start_internal
 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\rt.rs:148
36 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    main
 at unknown
37 File C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe: 
    invoke_main
 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    __scrt_common_main_seh
 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
38 File C:\windows\System32\KERNEL32.DLL: 
    BaseThreadInitThunk
 at unknown
39 File C:\windows\SYSTEM32\ntdll.dll: 
    RtlUserThreadStart
 at unknown

--------Frames--------
C:\windows\System32\KERNELBASE.dll
C:\Users\admin\AppData\Local\tauri-app\tauri-app.exe
C:\windows\SYSTEM32\ntdll.dll
C:\windows\System32\user32.dll
C:\windows\System32\KERNEL32.DLL
C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.4355_none_60b8b9eb71f62e16\comctl32.dll
----------------------
muwoo commented

I couldn't reproduce the crash unfortunately. If the crash happens because of repetitive calls in short time, it maybe the same bug as #10546

Mainly rust panic doesn't catch similar errors, so I'm not sure if it's the same problem