tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.15k stars 2.57k forks source link

[bug] corrupt when loading local hls files with asset protocol #3143

Closed conanchen closed 2 years ago

conanchen commented 2 years ago

Describe the bug

currupt when loading local hls files with asset protocol

Reproduction

  1. copied player code from vimejs
  2. used convertFileSrc

    
    <script lang="ts">
    import { convertFileSrc } from "@tauri-apps/api/tauri";
    
    import { onMount } from "svelte";
    
    let showPlayer = false;
    let player;
    
    onMount(async () => {
    const { defineCustomElements } = await import("@vime/core");
    defineCustomElements();
    showPlayer = true;
    });
    
    const posterlocal = convertFileSrc("/Users/CC/posterlocal.png");
    const datasrclocal = convertFileSrc(
    "/Users/CC/resources/master.m3u8"
    );
    console.log("posterlocal=", posterlocal, " datasrclocal=", datasrclocal);
    </script>
poster.png


{#if showPlayer} {/if}
``` ### Expected behavior load hls file m3u8 sucessfully ### Platform and versions ```shell ❯ cargo tauri info Operating System - Mac OS, version 12.1.0 X64 Node.js environment Node.js - 16.13.1 @tauri-apps/cli - 1.0.0-beta.10 @tauri-apps/api - 1.0.0-beta.8 Global packages npm - 8.1.2 pnpm - 6.24.2 yarn - 1.22.10 Rust environment rustc - 1.59.0-nightly cargo - 1.58.0-nightly Rust environment rustup - 1.24.3 rustc - 1.59.0-nightly cargo - 1.58.0-nightly toolchain - nightly-x86_64-apple-darwin (environment override by RUSTUP_TOOLCHAIN) App directory structure /@types /node_modules /datas /static /.github /src-tauri /.svelte-kit /build /.git /.vscode /.idea /src App tauri.rs - 1.0.0-beta.8 build-type - bundle CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: asset: customprotocol: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self' distDir - ../build devPath - http://localhost:3030/ framework - Svelte ``` ### Stack trace ```shell 2021-12-31 12:03:55.887007 UTC INFO may::io::sys::select - wakeup id=0, ret=0 2021-12-31 12:03:55.887852 UTC INFO may::io::sys::select - got wakeup event in select, id=0 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidRange', /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:346:78 stack backtrace: 0: 0x10cf09941 - std::backtrace_rs::backtrace::libunwind::trace::hd1f3f27a0ce98cd1 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x10cf09941 - std::backtrace_rs::backtrace::trace_unsynchronized::hd569a01ac3d00854 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x10cf09941 - std::sys_common::backtrace::_print_fmt::h996dd958d6ad6e0c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:67:5 3: 0x10cf09941 - ::fmt::hd97b45925762f035 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:46:22 4: 0x10cf2ca4b - core::fmt::write::h2d5ecb4b9764759c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/fmt/mod.rs:1149:17 5: 0x10cf00f2a - std::io::Write::write_fmt::h80cfd69766515533 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/io/mod.rs:1697:15 6: 0x10cf0b775 - std::sys_common::backtrace::_print::h811beb019f458a3f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:49:5 7: 0x10cf0b775 - std::sys_common::backtrace::print::h2568609b53248111 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:36:9 8: 0x10cf0b775 - std::panicking::default_hook::{{closure}}::h726902fd3b2e524f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:211:50 9: 0x10cf0b35f - std::panicking::default_hook::h8c88a86349ae0d96 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:228:9 10: 0x10bb2b7a4 - as core::ops::function::Fn>::call::h7e7d0fa5d9b607e1 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 11: 0x10bb49c99 - may::scheduler::filter_cancel_panic::{{closure}}::haac0632072a8a8ba at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/may-0.3.19/src/scheduler.rs:49:9 12: 0x10cf0be86 - std::panicking::rust_panic_with_hook::h5cbc51010430491b at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:610:17 13: 0x10cf0b8fe - std::panicking::begin_panic_handler::{{closure}}::hf90c83b4ac2013ae at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:502:13 14: 0x10cf09dc7 - std::sys_common::backtrace::__rust_end_short_backtrace::hca90c3f3f4640bf8 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:139:18 15: 0x10cf0b86a - rust_begin_unwind at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:498:5 16: 0x10cf52b1f - core::panicking::panic_fmt::h88a1b6fbb9084d2c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/panicking.rs:107:14 17: 0x10cf52c05 - core::result::unwrap_failed::h8abe20a396a5e82a at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/result.rs:1660:5 18: 0x10b415f78 - core::result::Result::unwrap::h86599c529547f483 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/result.rs:1342:23 19: 0x10b646a41 - tauri::manager::WindowManager::prepare_pending_window::{{closure}}::{{closure}}::h860235919876ac84 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:346:25 20: 0x10b370a07 - as core::future::future::Future>::poll::hdbb1f02938fa2a82 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/future/mod.rs:80:19 21: 0x10b570e01 - tokio::park::thread::CachedParkThread::block_on::{{closure}}::h005cba928abb745e at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:54 22: 0x10b64a621 - tokio::coop::with_budget::{{closure}}::h058ec82ff0e8435a at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:102:9 23: 0x10b4ba700 - std::thread::local::LocalKey::try_with::h5496337966fce81c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/thread/local.rs:413:16 24: 0x10b4b980e - std::thread::local::LocalKey::with::h37a4577b8f1a74ee at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/thread/local.rs:389:9 25: 0x10b57041c - tokio::coop::with_budget::h44b4baf2fa0493ab at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:95:5 26: 0x10b57041c - tokio::coop::budget::hdf257886ca87d845 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:72:5 27: 0x10b57041c - tokio::park::thread::CachedParkThread::block_on::h8d007173ad97c9fd at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:31 28: 0x10b55fb40 - tokio::runtime::enter::Enter::block_on::h0d15765e904823fb at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/enter.rs:151:13 29: 0x10b30cb95 - tokio::runtime::thread_pool::ThreadPool::block_on::ha848b1f82c47c834 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/thread_pool/mod.rs:77:9 30: 0x10b1f24e8 - tokio::runtime::Runtime::block_on::he11151ed87562583 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/mod.rs:463:43 31: 0x10b43a10b - tauri::async_runtime::Runtime::block_on::h0743c2bd78929f34 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:124:25 32: 0x10b436bb5 - tauri::async_runtime::GlobalRuntime::block_on::h1a4c1518de111ac5 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:72:7 33: 0x10b43a2e5 - tauri::async_runtime::block_on::h864fc13f5aca2c4f at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:259:3 34: 0x10b4379b7 - tauri::async_runtime::safe_block_on::hb15a52a6ec1cebfb at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:294:5 35: 0x10b645853 - tauri::manager::WindowManager::prepare_pending_window::{{closure}}::hd8620bfbf08a8ea1 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:339:46 36: 0x10b306a14 - tauri_runtime::window::PendingWindow::register_uri_scheme_protocol::{{closure}}::h373639f3e7c7ca2b at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime/src/window.rs:179:48 37: 0x10c7e135b - as core::ops::function::Fn>::call::h08045e6cc89def8c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 38: 0x10c76c4bd - tauri_runtime_wry::create_webview::{{closure}}::h91f599a551649051 at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime-wry/src/lib.rs:2628:7 39: 0x10c89155b - as core::ops::function::Fn>::call::hef627901c13d9e48 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 40: 0x10c86c26b - wry::webview::wkwebview::InnerWebView::new::start_task::ha2dcfe551dd04304 at /Users/CC/.cargo/git/checkouts/wry-0ba07c7b81cd1a87/3284f8d/src/webview/wkwebview/mod.rs:164:38 41: 0x7ff91baeec61 - 42: 0x7ff91bbdebbc - 43: 0x7ff91bba3c0f - 44: 0x7ff91bba3b79 - 45: 0x7ff91beced7b - 46: 0x7ff91b7df959 - 47: 0x7ff91bbd970b - 48: 0x7ff91b7bd3ce - 49: 0x7ff91b7bcba0 - 50: 0x7ff83107af3f - 51: 0x7ff83107be9a - 52: 0x7ff817aaf8fd - 53: 0x7ff817aaf865 - 54: 0x7ff817aaf5e4 - 55: 0x7ff817aae01b - 56: 0x7ff817aad5dd - 57: 0x7ff8206e04f1 - 58: 0x7ff8206e0247 - 59: 0x7ff8206dffe5 - 60: 0x7ff81a4dcb4c - 61: 0x7ff81a4db1b8 - 62: 0x7ff81a4cd5a9 - 63: 0x10c756086 - <() as objc::message::MessageArguments>::invoke::h4996b229a6f0ffb8 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17 64: 0x10c759f9c - objc::message::platform::send_unverified::h86c989ac1f33cd2a at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9 65: 0x10b561bcf - objc::message::send_message::h172ab26c98d9cc77 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5 66: 0x10b561bcf - tao::platform_impl::platform::event_loop::EventLoop::run_return::hf74d0f95e38adf7f at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/platform_impl/macos/event_loop.rs:180:16 67: 0x10b561e7d - tao::platform_impl::platform::event_loop::EventLoop::run::h0e9fd94ea6de5aca at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/platform_impl/macos/event_loop.rs:147:5 68: 0x10b2323bc - tao::event_loop::EventLoop::run::hdf59594d175bf82e at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/event_loop.rs:152:5 69: 0x10b5bd614 - ::run::h2114e098c156cddf at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime-wry/src/lib.rs:1881:5 70: 0x10b45481c - tauri::app::App::run::hc86b6175d9b11cc7 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/app.rs:480:5 71: 0x10b30c323 - ebmaster::main::ha0b218c1f73fe4bb at /Users/CC/xxxx/src-tauri/src/main.rs:260:3 72: 0x10b1b5b2e - core::ops::function::FnOnce::call_once::h0399af985b26312e at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/ops/function.rs:227:5 73: 0x10b5d04c1 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha15d4f9d5077d1dd at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:123:18 74: 0x10b5dbce4 - std::rt::lang_start::{{closure}}::hc03cf426bc4b8680 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:145:18 75: 0x10cf091a4 - core::ops::function::impls:: for &F>::call_once::he64439ea80c91c04 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/ops/function.rs:259:13 76: 0x10cf091a4 - std::panicking::try::do_call::h66ad3d2da0471c01 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:406:40 77: 0x10cf091a4 - std::panicking::try::h355714f8158880bc at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:370:19 78: 0x10cf091a4 - std::panic::catch_unwind::hf52738c273a0e724 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panic.rs:133:14 79: 0x10cf091a4 - std::rt::lang_start_internal::{{closure}}::hc160f80a2e430575 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:128:48 80: 0x10cf091a4 - std::panicking::try::do_call::hf89d9db6874b51b7 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:406:40 81: 0x10cf091a4 - std::panicking::try::hbf22e3fb725f11ab at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:370:19 82: 0x10cf091a4 - std::panic::catch_unwind::h70212148c0e249ee at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panic.rs:133:14 83: 0x10cf091a4 - std::rt::lang_start_internal::he76135267df4563a at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:128:20 84: 0x10b5dbcbe - std::rt::lang_start::hbf8d4b087bbfbd1f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:144:17 85: 0x10b30c4d6 - at /Users/CC/xxxx/src-tauri/src/main.rs:33:39 ``` ### Additional context _No response_
conanchen commented 2 years ago

I am using the latest tauri @next ,

❯ git log commit e784ebca9f5513ce07b63c15ccac4f51c14efe2f (HEAD -> next, origin/next, origin/HEAD) Author: Lucas Fernandes Nogueira lucasfernandesnog@gmail.com Date: Thu Dec 30 13:46:05 2021 -0300

fix(core): Send+Sync for Window, closes #3135 (#3140)

commit efbf236f35a1dd4064c0615b56881e4132a249f4 Author: Lucas Fernandes Nogueira lucasfernandesnog@gmail.com Date: Thu Dec 30 11:28:41 2021 -0300

lucasfernog commented 2 years ago

Thanks for the report. I'll look into this over the weekend.

lucasfernog commented 2 years ago

I don't think the webview supports loading m3u8 files directly. I also tried on Chrome and on Safari and it didn't work. Do you see any evidence this might work?

conanchen commented 2 years ago

asset::// protocol works with local m3u8 file. I added println! to manager.rs to check the range parsing


        // handle 206 (partial range) http request
        if let Some(range) = request.headers().get("range").cloned() {
          let mut status_code = 200;
          let path_for_data = path_for_data.clone();
          println!("path_for_data={}",path_for_data);
          let (headers, status_code, data) = crate::async_runtime::safe_block_on(async move {
            let mut headers = HashMap::new();
            let mut buf = Vec::new();
            let mut file = tokio::fs::File::open(path_for_data.clone()).await.unwrap();
            // Get the file size
            let file_size = file.metadata().await.unwrap().len();
            // parse the range
            let range_ = HttpRange::parse(range.to_str().unwrap(), file_size);

            println!("path_for_data file_size={} {:?} range_={:?}",file_size , range.to_str(), range_);

            let range = range_.unwrap();

            // FIXME: Support multiple ranges

and found it return an invalid range:

path_for_data file_size=375 Ok("bytes=0-*") range_=Err(InvalidRange)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidRange', /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:352:32

1. test with correct local m3u8 master and sub files , the player can play local m3u8 files

2022-01-04 14:57:47.177643 UTC INFO may::io::sys::select - got wakeup event in select, id=0 path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=0-326743") range=Ok([HttpRange { start: 0, length: 326744 }]) path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=326744-653111") range=Ok([HttpRange { start: 326744, length: 326368 }]) path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=653112-980231") range=Ok([HttpRange { start: 653112, length: 327120 }]) path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=980232-1306787") range=Ok([HttpRange { start: 980232, length: 326556 }]) path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=1306788-1633155") range=Ok([HttpRange { start: 1306788, length: 326368 }]) path_for_data=/Users/CC/xxxx/bipbop-advanced/gear1/main.ts path_for_data filesize=59366640 Ok("bytes=1633156-1960839") range=Ok([HttpRange { start: 1633156, length: 327684 }])

2. same as step 1, if I switch the player page to another page , corrupt:

path_for_data=/Users/CC/xxxx/bipbop-advanced/bipbop_16x9_variant.m3u8
path_for_data file_size=2326 Ok("bytes=0-*") range_=Err(InvalidRange)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidRange', /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:352:32
stack backtrace:
   0:        0x110d82001 - std::backtrace_rs::backtrace::libunwind::trace::hd1f3f27a0ce98cd1
                               at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5

3. test with correct local m3u8 master files, if open the introspection tab, corrupt:

2022-01-04 14:54:19.659310 UTC INFO may::io::sys::select - got wakeup event in select, id=0 path_for_data=/Users/CC/xxxxx/master.m3u8 path_for_data filesize=375 Ok("bytes=0-*") range=Err(InvalidRange) thread 'main' panicked at 'called Result::unwrap() on an Err value: InvalidRange', /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:352:32 stack backtrace: 0: 0x1064e7001 - std::backtrace_rs::backtrace::libunwind::trace::hd1f3f27a0ce98cd1 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x1064e7001 - std::backtrace_rs::backtrace::trace_unsynchronized::hd569a01ac3d00854 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x1064e7001 - std::sys_common::backtrace::_print_fmt::h996dd958d6ad6e0c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:67:5 3: 0x1064e7001 - ::fmt::hd97b45925762f035 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:46:22 4: 0x10650a10b - core::fmt::write::h2d5ecb4b9764759c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/fmt/mod.rs:1149:17 5: 0x1064de5ea - std::io::Write::write_fmt::h80cfd69766515533 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/io/mod.rs:1697:15 6: 0x1064e8e35 - std::sys_common::backtrace::_print::h811beb019f458a3f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:49:5 7: 0x1064e8e35 - std::sys_common::backtrace::print::h2568609b53248111 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:36:9 8: 0x1064e8e35 - std::panicking::default_hook::{{closure}}::h726902fd3b2e524f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:211:50 9: 0x1064e8a1f - std::panicking::default_hook::h8c88a86349ae0d96 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:228:9 10: 0x105108c44 - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::h7e7d0fa5d9b607e1 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 11: 0x105127139 - may::scheduler::filter_cancel_panic::{{closure}}::haac0632072a8a8ba at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/may-0.3.19/src/scheduler.rs:49:9 12: 0x1064e9546 - std::panicking::rust_panic_with_hook::h5cbc51010430491b at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:610:17 13: 0x1064e8fbe - std::panicking::begin_panic_handler::{{closure}}::hf90c83b4ac2013ae at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:502:13 14: 0x1064e7487 - std::sys_common::backtrace::rust_end_short_backtrace::hca90c3f3f4640bf8 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:139:18 15: 0x1064e8f2a - rust_begin_unwind at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:498:5 16: 0x1065301df - core::panicking::panic_fmt::h88a1b6fbb9084d2c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/panicking.rs:107:14 17: 0x1065302c5 - core::result::unwrap_failed::h8abe20a396a5e82a at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/result.rs:1660:5 18: 0x1049f7218 - core::result::Result<T,E>::unwrap::h86599c529547f483 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/result.rs:1342:23 19: 0x104c22176 - tauri::manager::WindowManager::prepare_pending_window::{{closure}}::{{closure}}::h93751dfb06a1f688 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:352:25 20: 0x10494c867 - <core::future::from_generator::GenFuture as core::future::future::Future>::poll::h859cfd0e737d69de at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/future/mod.rs:80:19 21: 0x104b4df41 - tokio::park::thread::CachedParkThread::block_on::{{closure}}::hc9e12b6521cdb66a at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:54 22: 0x104c26221 - tokio::coop::with_budget::{{closure}}::h6e86ad383d957e89 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:102:9 23: 0x104a95470 - std::thread::local::LocalKey::try_with::h7122500f888f1766 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/thread/local.rs:413:16 24: 0x104a93d9e - std::thread::local::LocalKey::with::h06ef627babb43fbd at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/thread/local.rs:389:9 25: 0x104b4d03c - tokio::coop::with_budget::h01f3ddee18ae41e6 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:95:5 26: 0x104b4d03c - tokio::coop::budget::h808b020f31d28576 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/coop.rs:72:5 27: 0x104b4d03c - tokio::park::thread::CachedParkThread::block_on::h0a0b40063fa04d4d at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/park/thread.rs:263:31 28: 0x104a3c080 - tokio::runtime::enter::Enter::block_on::hfe817823673d12cd at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/enter.rs:151:13 29: 0x104c17a55 - tokio::runtime::thread_pool::ThreadPool::block_on::h9f0f3ad4ae3adf00 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/thread_pool/mod.rs:77:9 30: 0x1047ce5f8 - tokio::runtime::Runtime::block_on::he66486c04ac7b930 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/runtime/mod.rs:463:43 31: 0x104a1c0fb - tauri::async_runtime::Runtime::block_on::h4c99e8f8294ccb66 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:124:25 32: 0x104a18c95 - tauri::async_runtime::GlobalRuntime::block_on::h83b580e1eed98f33 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:72:7 33: 0x104a1c2d5 - tauri::async_runtime::block_on::hb17e62cdb37da0ae at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:259:3 34: 0x104a199a7 - tauri::async_runtime::safe_block_on::h2e8b0646865939a6 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/async_runtime.rs:294:5 35: 0x104c20d0f - tauri::manager::WindowManager::prepare_pending_window::{{closure}}::hd8620bfbf08a8ea1 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/manager.rs:340:46 36: 0x1048e5794 - tauri_runtime::window::PendingWindow::register_uri_scheme_protocol::{{closure}}::h373639f3e7c7ca2b at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime/src/window.rs:179:48 37: 0x105dbe85b - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::h08045e6cc89def8c at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 38: 0x105d499bd - tauri_runtime_wry::create_webview::{{closure}}::h91f599a551649051 at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime-wry/src/lib.rs:2628:7 39: 0x105e6ea5b - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::hef627901c13d9e48 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/alloc/src/boxed.rs:1825:9 40: 0x105e4976b - wry::webview::wkwebview::InnerWebView::new::start_task::ha2dcfe551dd04304 at /Users/CC/.cargo/git/checkouts/wry-0ba07c7b81cd1a87/3284f8d/src/webview/wkwebview/mod.rs:164:38 41: 0x7ff90458bc61 - 42: 0x7ff90467bbbc - 43: 0x7ff904640c0f - 44: 0x7ff904640b79 - 45: 0x7ff90496bd7b - 46: 0x7ff90427c959 - 47: 0x7ff90467670b - 48: 0x7ff90425a3ce - 49: 0x7ff904259ba0 - 50: 0x7ff819b17f3f - 51: 0x7ff819b18e9a - 52: 0x7ff80054c8fd - 53: 0x7ff80054c865 - 54: 0x7ff80054c5e4 - 55: 0x7ff80054b01b - 56: 0x7ff80054a5dd - 57: 0x7ff80917d4f1 - 58: 0x7ff80917d247 - 59: 0x7ff80917cfe5 - 60: 0x7ff802f79b4c - 61: 0x7ff802f781b8 - 62: 0x7ff802f6a5a9 - 63: 0x105d33586 - <() as objc::message::MessageArguments>::invoke::h4996b229a6f0ffb8 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17 64: 0x105d3749c - objc::message::platform::send_unverified::h86c989ac1f33cd2a at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9 65: 0x104b3e19f - objc::message::send_message::h172ab26c98d9cc77 at /Users/CC/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5 66: 0x104b3e19f - tao::platform_impl::platform::event_loop::EventLoop::run_return::hf74d0f95e38adf7f at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/platform_impl/macos/event_loop.rs:180:16 67: 0x104b3e44d - tao::platform_impl::platform::event_loop::EventLoop::run::h0e9fd94ea6de5aca at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/platform_impl/macos/event_loop.rs:147:5 68: 0x10489b13c - tao::event_loop::EventLoop::run::hdf59594d175bf82e at /Users/CC/.cargo/git/checkouts/tao-b2c91e21b396bd53/d380100/src/event_loop.rs:152:5 69: 0x104b987b4 - ::run::h2114e098c156cddf at /Users/CC/github/tauri-apps/tauri/core/tauri-runtime-wry/src/lib.rs:1881:5 70: 0x104a35b6c - tauri::app::App::run::hc86b6175d9b11cc7 at /Users/CC/github/tauri-apps/tauri/core/tauri/src/app.rs:480:5 71: 0x1048eb963 - ebmaster::main::ha0b218c1f73fe4bb at /Users/CC/xxxx/src-tauri/src/main.rs:260:3 72: 0x104791b9e - core::ops::function::FnOnce::call_once::h0399af985b26312e at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/ops/function.rs:227:5 73: 0x104bac291 - std::sys_common::backtrace::rust_begin_short_backtrace::ha15d4f9d5077d1dd at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/sys_common/backtrace.rs:123:18 74: 0x104a868b4 - std::rt::lang_start::{{closure}}::hc03cf426bc4b8680 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:145:18 75: 0x1064e6864 - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::he64439ea80c91c04 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/core/src/ops/function.rs:259:13 76: 0x1064e6864 - std::panicking::try::do_call::h66ad3d2da0471c01 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:406:40 77: 0x1064e6864 - std::panicking::try::h355714f8158880bc at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:370:19 78: 0x1064e6864 - std::panic::catch_unwind::hf52738c273a0e724 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panic.rs:133:14 79: 0x1064e6864 - std::rt::lang_start_internal::{{closure}}::hc160f80a2e430575 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:128:48 80: 0x1064e6864 - std::panicking::try::do_call::hf89d9db6874b51b7 at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:406:40 81: 0x1064e6864 - std::panicking::try::hbf22e3fb725f11ab at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panicking.rs:370:19 82: 0x1064e6864 - std::panic::catch_unwind::h70212148c0e249ee at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/panic.rs:133:14 83: 0x1064e6864 - std::rt::lang_start_internal::he76135267df4563a at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:128:20 84: 0x104a8688e - std::rt::lang_start::hbf8d4b087bbfbd1f at /rustc/efec545293b9263be9edfb283a7aa66350b3acbf/library/std/src/rt.rs:144:17 85: 0x1048ebb16 - at /Users/CC/xxxx/src-tauri/src/main.rs:33:39

conanchen commented 2 years ago

test with below updated manager.rs by checking file/range before unwrap(), works now.


        // handle 206 (partial range) http request
        if let Some(range) = request.headers().get("range").cloned() {
          let mut status_code = 200;
          let path_for_data = path_for_data.clone();
          println!("path_for_data={}", path_for_data);
          let (headers, status_code, data) = crate::async_runtime::safe_block_on(async move {
            let mut headers = HashMap::new();
            let mut buf = Vec::new();
            let mut file = tokio::fs::File::open(path_for_data.clone()).await;

            if file.is_ok() {
              let mut file_ = file.unwrap();
              // Get the file size
              let file_size = file_.metadata().await.unwrap().len();
              let file_size_ = format!("{}", file_size);
              let ss = range.to_str().unwrap();
              // parse the range
              let range_ = HttpRange::parse(&ss.replace("*", &file_size_), file_size);

              println!(
                "path_for_data file_size={} {:?} range_={:?}",
                file_size,
                range.to_str(),
                range_
              );

              let range = range_.unwrap();

              // FIXME: Support multiple ranges