Skip to content

fix(core): load asset protocol files asynchronously - #16050

Merged
Legend-Master merged 4 commits into
tauri-apps:devfrom
PathGao:fix/asset-protocol-off-main-thread
Sep 21, 2026
Merged

Legend-Master merged 4 commits into
tauri-apps:devfrom
PathGao:fix/asset-protocol-off-main-thread

Conversation

@PathGao

@PathGao PathGao commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7434.

If an asset:// file sits on a slow or unreachable path, like a network share that's down, the whole app freezes, every window. The handler reads the file right on the thread that runs the event loop.

This makes the handler async, the same way #15220 did for tauri://: file access goes back to tokio::fs (undoing the asset.rs part of #15117), and the handler responds from a spawned task. Markpad has shipped the same idea as its own asset handler since August.

Verification on macOS arm64:

cargo test -p tauri --lib --all-features protocol::asset
cargo clippy -p tauri --all-features --lib --tests

I also ran a local test (not included) that reads from a FIFO, which blocks like a dead share. It times out on dev and passes with this change.

@PathGao
PathGao requested a review from a team as a code owner September 17, 2026 09:50
@Legend-Master

Copy link
Copy Markdown
Contributor

I think you might want to re-open #15836 instead

@PathGao

PathGao commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

I'd have liked to, but I deleted the fork that PR came from, so GitHub won't let me reopen it. This is the same change, rebased onto current dev.

@PathGao

PathGao commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

It's also smaller than #15836: just the handler change and a change file, without the FIFO test. Happy to add the test back if you want it.

@Legend-Master

Legend-Master commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

I'd have liked to, but I deleted the fork that PR came from, so GitHub won't let me reopen it. This is the same change, rebased onto current dev.

Got it, I'm fine with either one of them.

Since everything here can be async (through tokio), we should revert the changes made in #15117 and mirror #15220 for it to run as an async task, no need to block here.

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Package Changes Through 89b276d

There are 14 changes which include tauri-cli with minor, @tauri-apps/cli with minor, tauri with minor, tauri-build with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, @tauri-apps/api with minor, tauri-bundler with minor, tauri-macos-sign with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.11.1 2.12.0
tauri-utils 2.9.3 2.10.0
tauri-macos-sign 2.3.4 2.4.0
tauri-bundler 2.9.4 2.10.0
tauri-runtime 2.11.3 2.12.0
tauri-runtime-wry 2.11.4 2.12.0
tauri-codegen 2.6.3 2.7.0
tauri-macros 2.6.3 2.7.0
tauri-plugin 2.6.3 2.7.0
tauri-build 2.6.3 2.7.0
tauri 2.11.5 2.12.0
@tauri-apps/cli 2.11.4 2.12.0
tauri-cli 2.11.4 2.12.0
tauri-driver 2.0.6 2.1.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@PathGao PathGao changed the title fix(core): read asset protocol files off the event loop thread fix(core): load asset protocol files asynchronously Sep 17, 2026
@PathGao

PathGao commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Done. It's async now like #15220: tokio::fs again, and the handler responds from a spawned task.

@Tunglies

Copy link
Copy Markdown
Contributor

Any benchmark cloud be sharing? It seemed using async in sync scope makes no reason, unless using tokio::spawn_blocking in sync scope, but it produce threads of tokio.

@Tunglies

Copy link
Copy Markdown
Contributor

Also, block_on would process async codes as sync. The await does nothing, it still needs to wait to process hole codes inside.

@PathGao

PathGao commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

There's no block_on in the handler. It spawns the task and returns right away, and the task calls the responder once the file is read. The only block_on is in the test.

This isn't about speed, so I don't have a benchmark. The handler runs on the event loop thread, so a read that hangs (like a network share that's down) used to freeze every window. Now it doesn't.

You're right that tokio::fs uses tokio's blocking threads underneath. The first version of this PR used spawn_blocking directly. Legend-Master asked for the async version to match #15220.

Comment thread crates/tauri/src/protocol/asset.rs Resolved
@Legend-Master

Copy link
Copy Markdown
Contributor

Any benchmark cloud be sharing? It seemed using async in sync scope makes no reason, unless using tokio::spawn_blocking in sync scope, but it produce threads of tokio.

This is not about performance but rather not blocking the main thread on reading files.

Also, block_on would process async codes as sync. The await does nothing, it still needs to wait to process hole codes inside.

That is only used in tests so...

@Legend-Master Legend-Master left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Legend-Master
Legend-Master merged commit 127aa17 into tauri-apps:dev Sep 21, 2026
23 checks passed
@PathGao
PathGao deleted the fix/asset-protocol-off-main-thread branch September 21, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] load image file by asset protocol from smb will hang the entire application.

3 participants