#emit_all from app handle panics: Runtime(FailedToSendMessage)

6 messages · Page 1 of 1 (latest)

cinder smelt
#

Hi all,
I'm creating an app that downloads audio files from our server. In order to denote a files download status (percent), I have the app handle emit an event after each read:

// While we have a chunk that's valid coming from the stream
while let Some(chunk) = stream.next().await {
    // Grab another lock on our files
    let mut progress_file_lock = download_state.files.lock().await;
    // Grab the bytes then write them to the file
    let chunk = chunk?;
    file.write_all(&chunk)?;
    // Add onto the progress
    progress += chunk.len() as u64;
    // Store our progress as a fraction against the file
    let percentage = progress as f64 / total_size as f64;
    progress_file_lock[index].progress = percentage;
    // Drop the progress file lock so that we can emit the change in download state
    drop(progress_file_lock);

    // Convert into a payload that we can use
    let payload = download_state.convert_into_payload().await;

    // Now that we have our converted data, emit it to the front-end
    app_handle.emit_all("download_state_updated", payload).unwrap();
}

However, I found that on downloading over 100 files, I received this error when unwrapping the emit event:
Runtime(FailedToSendMessage)

Has anyone encountered this before and what it means? I haven't been able to find much in the way of documentation. Thank you!

young monolith
#

Please provide the output of tauri info.

#

This is pretty common on Windows when the IPC is flooded with messages.

cinder smelt
#

tauri info dump:

[✔] Environment
    - OS: Windows 10.0.19045 X64
    ✔ WebView2: 123.0.2420.97
    ✔ MSVC:
        - Visual Studio Build Tools 2022
        - Visual Studio Community 2022
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.12.2
    - yarn: 1.22.4
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 1.5.4
    - tauri-build [RUST]: 1.5.1
    - tao [RUST]: 0.16.5
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.9 (outdated, latest: 1.5.11)

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

I wasn't aware that it could get clogged up. In this case, should I only be emitting commands every X seconds or something if the download takes a while? Thank you for the help

young monolith
#

I don't think there's a specific time-based threshold. As I understand it, the internal buffer of the webview is small and it's not reading out that buffer before it gets filled with new messages. The impact was mitigated in the upload plugin by sending a cumulative total of the last 10 stream chunks. It's not a perfect fix because enough IPC messages will cause it to start happening again.