Skip to content

fix(network): harden manual host add timeout handling - #36

Merged
qiin2333 merged 3 commits into
masterfrom
codex/fix-manual-add-timeouts
Jun 13, 2026
Merged

fix(network): harden manual host add timeout handling#36
qiin2333 merged 3 commits into
masterfrom
codex/fix-manual-add-timeouts

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 手动添加主机时,/serverinfo 探测遇到瞬时网络错误会快速重试一次,专治那种一次 timeout 就装死的杂鱼状态。
  • NvHttp.getServerInfo(likelyOnline) 现在真的会按 likelyOnline 选择 5s/3s 连接超时,并让 HTTPS 端口懒解析、HTTP 降级沿用同一连接超时。
  • 轮询只在“已在线且当前活跃地址”场景使用长连接超时,避免后台探测被无意义拖慢。
  • 请求 helper 和内部添加主机 helper 改成 options 形态,去掉 undefined, true 这种读起来会绊脚的参数排列。

为啥要改

用户反馈手动添加主机时报 HTTP 请求失败: Timeout was reached,但 Android 客户端同一时间可以连接。对照 Android 后发现我们有几处更容易放大 HarmonyOS/RCP 偶发超时的问题:手动添加没有轻量重试,likelyOnline 参数没有实际接入连接超时策略,轮询调用也没有区分活跃在线地址。

验证

  • git diff --check
  • $env:DEVECO_SDK_HOME='C:\Program Files\Huawei\DevEco Studio\sdk'; $env:JAVA_HOME='C:\Program Files\Huawei\DevEco Studio\jbr'; $env:PATH="$env:JAVA_HOME\bin;$env:PATH"; & 'C:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin\hvigorw.bat' --no-daemon assembleHap

构建已通过。现有项目级 ArkTS warning 仍然存在,但不是这次改动引入的,杂鱼 warning 们先排队。

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@qiin2333, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 741fdab1-b246-4c93-ab01-cf2e1844d545

📥 Commits

Reviewing files that changed from the base of the PR and between 971365e and e5c8b30.

📒 Files selected for processing (5)
  • entry/src/main/ets/service/streaming/NvHttp.ets
  • entry/src/main/module.json5
  • entry/src/main/resources/base/element/string.json
  • scripts/devkey-gen.js
  • scripts/红焖v+算号器.html
📝 Walkthrough

概览

PR 通过引入 options 对象,统一重构 NvHttp 的请求接口(超时、证书参数),并改进 ComputerManager 的计算机添加流程以支持手动添加时的鲁棒重试和 mDNS 发现时的参数传递,同时优化了轮询时的上线状态检测。

变更详情

HTTP 请求参数化与计算机添加流程重构

层 / 文件(s) 概述
NvHttp 请求类型与核心 doRequest 重构
entry/src/main/ets/service/streaming/NvHttp.ets
新增 NvHttpRequestOptionsNvHttpPathRequestOptions 接口,将 doRequest 从位置参数 (url, timeout, useClientCert) 改为 options 形式,根据 useClientCert 字段分支选择 HttpClient.getWithClientCertHttpClient.get,统一下传 connectTimeouttransferTimeout
NvHttp HTTPS 发现与 FRP 重试流程
entry/src/main/ets/service/streaming/NvHttp.ets
getHttpsBaseUrl 接收 connectTimeout 参数并在 HTTP 自动探测时传给 doRequestdoHttpsWithFrpRetrydoHttpsRequestWithFrpRetry 改为接收 NvHttpPathRequestOptions,在重试时通过新的 doRequest 接口传递证书与超时配置。
NvHttp getServerInfo 集成与连接超时参数化
entry/src/main/ets/service/streaming/NvHttp.ets
getServerInfo 引入 connectTimeout 变量,在 HTTPS(含 FRP 重试)与证书错误降级到 HTTP 的分支中统一调用 doRequest(url, {connectTimeout}),建立单一的参数流向。
NvHttp 应用控制与显示命令调用更新
entry/src/main/ets/service/streaming/NvHttp.ets
launchAppresumeAppquitAppsetBitratesendSuperCmdpcSleeprotateDisplaygetDisplaysgetAbrCapabilities 的 HTTPS 调用改用 doRequest({transferTimeout, useClientCert}) 形式,补齐关键参数,其中 getDisplays 使用 LONG_CONNECTION_TIMEOUT 以支持长连接。
ComputerManager 添加选项接口与常量
entry/src/main/ets/service/ComputerManager.ets
新增 AddComputerInternalOptions 接口承载 discoveredNamehttpPortdiscoveredIpv6robustServerInfo 字段;定义 MANUAL_ADD_SERVERINFO_ATTEMPTSMANUAL_ADD_RETRY_DELAY_MS 常量驱动手动添加时的重试机制。
ComputerManager 添加流程重构
entry/src/main/ets/service/ComputerManager.ets
handleDiscoveredComputer 调用改为传递 options 对象(mDNS 发现的名称、HTTP 端口、IPv6);addComputer 构造 manualAddOptions 启用 robustServerInfo,并在首次尝试与 IPv6 回退中复用该选项;addComputerInternal 根据 robustServerInfo 选择 getServerInfoRobust()getServerInfo(false),实现手动添加的鲁棒重试。
ComputerManager 轮询上线检测与 getServerInfo 参数
entry/src/main/ets/service/ComputerManager.ets
tryPollAddress 计算 likelyOnline 布尔值(轮询地址与计算机地址相符时为真),将其作为参数传入 nvHttp.getServerInfo(likelyOnline),使服务器信息获取能根据设备可能状态优化策略。

审查工作量评估

🎯 3 (中等) | ⏱️ ~20 分钟

可能相关的 PR

  • AlkaidLab/moonlight-harmony#18:两个 PR 都修改 NvHttp.etsgetServerInfo/HTTPS 重试行为,本 PR 通过 options 重构请求接口,相关 PR 则重构 frp HTTPS 端口重试机制。
  • AlkaidLab/moonlight-harmony#15:两个 PR 修改 ComputerManager.ets 的相同代码路径(addComputerInternaltryPollAddress),本 PR 通过 options 重构添加流程,相关 PR 则改进 NvHttp HTTPS 端口和服务器信息集成。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR标题清晰准确地总结了主要改动:改进手动添加主机时的超时处理机制,与代码变更内容完全相符。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-manual-add-timeouts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qiin2333
qiin2333 marked this pull request as ready for review June 13, 2026 16:42

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
entry/src/main/ets/service/streaming/NvHttp.ets (1)

489-496: 💤 Low value

参数 timeout 未被使用。

doHttpsWithFrpRetrytimeout 参数(第492行)在函数体内从未被引用。实际的传输超时由调用方通过 request lambda 闭包捕获。建议移除此冗余参数以避免混淆。

♻️ 建议移除未使用参数
  private async doHttpsWithFrpRetry<T>(
    path: string,
    query: string | undefined,
-   timeout: number,
    request: (url: string) => Promise<T>,
    connectTimeout: number = NvHttp.CONNECTION_TIMEOUT
  ): Promise<T> {

同时更新调用方:

- return this.doHttpsWithFrpRetry(path, options?.query, transferTimeout, (url: string): Promise<string> => {
+ return this.doHttpsWithFrpRetry(path, options?.query, (url: string): Promise<string> => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entry/src/main/ets/service/streaming/NvHttp.ets` around lines 489 - 496,
Remove the unused timeout parameter from doHttpsWithFrpRetry: update the method
signature (function doHttpsWithFrpRetry<T>(path: string, query: string |
undefined, request: (url: string) => Promise<T>, connectTimeout: number =
NvHttp.CONNECTION_TIMEOUT): Promise<T>) and all call sites that pass a timeout
to stop supplying that argument; leave the request lambda as-is (it already
captures any needed per-call timeout) and keep connectTimeout's default behavior
unchanged so no other internal logic needs modification.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@entry/src/main/ets/service/streaming/NvHttp.ets`:
- Around line 489-496: Remove the unused timeout parameter from
doHttpsWithFrpRetry: update the method signature (function
doHttpsWithFrpRetry<T>(path: string, query: string | undefined, request: (url:
string) => Promise<T>, connectTimeout: number = NvHttp.CONNECTION_TIMEOUT):
Promise<T>) and all call sites that pass a timeout to stop supplying that
argument; leave the request lambda as-is (it already captures any needed
per-call timeout) and keep connectTimeout's default behavior unchanged so no
other internal logic needs modification.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 38bdd4a4-7634-4786-b841-765f651de66b

📥 Commits

Reviewing files that changed from the base of the PR and between 3d6cfb6 and 971365e.

📒 Files selected for processing (2)
  • entry/src/main/ets/service/ComputerManager.ets
  • entry/src/main/ets/service/streaming/NvHttp.ets

@qiin2333
qiin2333 force-pushed the codex/fix-manual-add-timeouts branch from 9fe198e to 99d6b64 Compare June 13, 2026 16:54
@qiin2333
qiin2333 merged commit 4798db1 into master Jun 13, 2026
1 of 2 checks passed
@qiin2333
qiin2333 deleted the codex/fix-manual-add-timeouts branch June 13, 2026 17:03
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.

1 participant