fix(remote-connect): prevent rustls CryptoProvider panic on reconnect#1101
Open
ococl wants to merge 1 commit into
Open
fix(remote-connect): prevent rustls CryptoProvider panic on reconnect#1101ococl wants to merge 1 commit into
ococl wants to merge 1 commit into
Conversation
- Install ring CryptoProvider early at desktop startup to avoid duplicate install_default() races between reqwest and tokio-tungstenite
- Wrap Windows TLS connector construction in catch_unwind for defense-in-depth
- Enable explicit rustls features [ring, std, tls12] in Cargo.toml
- Adapt relay-server routes to axum 0.8 path param syntax ({room_id}, {*rest})
- Add mobile-web dev scripts to package.json
- Add .codebuddy to .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(remote-connect): prevent rustls CryptoProvider panic on reconnect
install_default()races between reqwest and tokio-tungstenitecatch_unwindfor defense-in-depth[ring, std, tls12]inCargo.toml{room_id},{*rest})package.json.codebuddyto.gitignoreSummary
修复远程控制(remote-connect)在连接/重连时进程崩溃的问题。
在
rustls 0.23且default-features = false的配置下,进程内多个组件(reqwest、tokio-tungstenite)可能在各自初始化时尝试调用install_default()安装CryptoProvider。第二次调用会触发 panic,在远程控制重连(reconnect)场景中导致 tokio task unwind,最终引发桌面程序崩溃。本次修复通过在 desktop 启动早期统一安装
CryptoProvider,并在 TLS connector 构建处增加catch_unwind兜底,彻底消除该崩溃路径。Type and Areas
Type:
bug fix
Areas:
Rust core, desktop/Tauri, server/relay
Motivation / Impact
问题:当用户在使用远程控制功能时,如果网络出现波动触发自动重连,桌面端有一定概率直接崩溃退出。
根因:
rustls 0.23+在default-features = false模式下不提供默认的CryptoProvider。reqwest和tokio-tungstenite都会在首次 TLS 操作时尝试调用rustls::crypto::ring::default_provider().install_default()。该函数在 provider 已安装时会 panic(而非返回错误),因此在重连路径上极易触发第二次安装,导致整个 tokio task unwind,进而拖垮进程。解决方案:
bitfun-desktop启动早期调用ensure_rustls_crypto_provider(),确保进程生命周期内只安装一次。dial()函数中,使用std::panic::catch_unwind包裹build_windows_rustls_connector(),即使出现意料之外的 panic,也能将其转换为Result::Err,避免扩散到 tokio runtime。Cargo.toml中为rustls显式启用ring、std、tls12特性,避免隐式依赖缺失。额外变更:
relay-server的路由参数语法从:room_id更新为{room_id}(axum 0.8 兼容性修复)。package.json新增若干mobile-web开发脚本(开发体验改进)。.gitignore新增.codebuddy。Verification
cargo check --workspace✅ 通过cargo check -p bitfun-desktop✅ 通过Reviewer Notes
未采纳的AI审计建议
在代码审计阶段,AI提出了以下两项改进建议。经评估,本次 PR 暂不采纳,原因如下:
1. 统一非 Windows 平台逻辑
未采纳原因:当前非 Windows 分支在
dial()内部已手动调用install_default(),且tokio-tungstenite在非 Windows 平台内置了自动处理逻辑。由于不清楚上游作者(rustls / tokio-tungstenite)在跨平台场景下的完整设计意图,为避免引入不必要的兼容性风险,暂时保持现有实现不变。2. 增强
catch_unwind错误信息未采纳原因:
catch_unwind在此处主要作为 defense-in-depth(纵深防御)手段。若桌面启动时的ensure_rustls_crypto_provider()已成功执行,则build_windows_rustls_connector内部理论上不应再因install_default()而 panic。保留简洁的错误转换即可满足当前需求,暂不需要增加额外的 downcast 逻辑。其他说明
BitFun-Installer/src-tauri/gen/schemas/*为 Tauri 构建自动生成文件,随 desktop 侧的改动同步更新。Checklist