Skip to content

fix(network): 临时禁用 HTTP/3 以缓解 dotnet/runtime#114128#3243

Merged
RyogiMutsuki merged 1 commit into
devfrom
fix/quic-exception
Jun 24, 2026
Merged

fix(network): 临时禁用 HTTP/3 以缓解 dotnet/runtime#114128#3243
RyogiMutsuki merged 1 commit into
devfrom
fix/quic-exception

Conversation

@SALTWOOD

@SALTWOOD SALTWOOD commented Jun 23, 2026

Copy link
Copy Markdown
Member

This resolves #3226.
根据本人探索,此问题是由 dotnet/runtime#114128 引起的。.NET 的 HTTP/3 实现在 stream abort 时会把 QuicException 挂到内部 Task,无法从请求调用点 catch,导致这个异常没有经过任何 try catch,而是直接走到了 TaskScheduler.UnobservedTaskException

此问题在 .NET 10 被修复,主项目版本却仍为 .NET 8,因此,此问题应当在升级至 .NET 10 之后解决。

综上所述,解决此问题只有两个方法:

  1. 升级至 .NET 10
  2. 禁用强制 HTTP/3

由于仍有一部分用户的系统版本较低,因此升级至 .NET 10 还需要一定时间。所以此问题的最佳修复方案是禁用强制 HTTP/3,在有条件升级至 .NET 10 之后回退此更改

Summary by Sourcery

Bug Fixes:

  • 通过不再对这些请求强制使用 HTTP/3,避免在图片下载过程中因未处理的 HTTP/3 QUIC 异常而导致的崩溃。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Avoid crashes caused by unhandled HTTP/3 QUIC exceptions during image downloads by no longer forcing HTTP/3 for these requests.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 labels Jun 23, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
评审者指南(在小型 PR 上折叠)

评审者指南

此 PR 暂时停止强制使用 HTTP/3 进行图片下载请求,以避免在 .NET 8 中出现无法捕获的 QuicException 问题;在项目升级到 .NET 10 之前,允许进行 HTTP 版本协商/使用 HTTP/2。

未强制 HTTP/3 情况下的图片下载时序图

sequenceDiagram
    participant MyImage
    participant HttpRequest
    participant Server

    MyImage->>HttpRequest: Create(url)
    activate HttpRequest
    HttpRequest-->>MyImage: HttpRequestInstance
    deactivate HttpRequest

    MyImage->>HttpRequest: SendAsync(addMetedata: false)
    activate HttpRequest
    rect rgb(230,230,230)
        Note over HttpRequest: HTTP version negotiated by runtime
    end
    HttpRequest->>Server: HTTP request (HTTP2_or_HTTP3)
    Server-->>HttpRequest: HTTP response
    deactivate HttpRequest

    MyImage->>MyImage: EnsureSuccessStatusCode()
    MyImage->>MyImage: WriteTo FileStream(tempDownloadingPath)
Loading

文件级变更

变更 详情 文件
停止在发出图片下载的 HTTP 请求时强制使用 HTTP/3,改为允许运行时时协商选择兼容的 HTTP 版本,从而避免与 QuicException 相关的崩溃路径。
  • 从图片下载逻辑使用的 HTTP 请求构造器中移除了显式的 HTTP/3 版本选项
  • 保留了现有的下载流程、响应处理和文件 I/O,因此行为变化仅限于所选用的 HTTP 协议版本
Plain Craft Launcher 2/Controls/MyImage.cs

针对关联问题的评估

问题 目标 是否解决 说明
#3226 防止在网络较差的情况下,在“社区资源”板块(例如 Mods)翻页下载时出现“未观测到的异步任务异常”(UnobservedTaskException)错误。

提示与命令

与 Sourcery 交互

  • 触发新的评审: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub issue: 在某条评审评论下回复,请 Sourcery 从该评论创建 issue。你也可以在评论中回复 @sourcery-ai issue,从该评论创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 总结: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在指定位置生成 PR 总结。你也可以在 pull request 中评论 @sourcery-ai summary 来在任意时间(重新)生成总结。
  • 生成评审者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成评审者指南。
  • 批量解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 评审: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 评审。特别适用于你想从头开始新的评审时——别忘了再评论 @sourcery-ai review 以触发新的评审!

自定义你的使用体验

前往你的 控制面板 以:

  • 启用或禁用诸如 Sourcery 生成的 pull request 总结、评审者指南等评审功能。
  • 更改评审语言。
  • 添加、移除或编辑自定义评审指令。
  • 调整其他评审设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR temporarily disables forcing HTTP/3 for image download requests to avoid an uncatchable QuicException issue in .NET 8, allowing HTTP version negotiation/HTTP/2 instead until the project upgrades to .NET 10.

Sequence diagram for image download without forced HTTP3

sequenceDiagram
    participant MyImage
    participant HttpRequest
    participant Server

    MyImage->>HttpRequest: Create(url)
    activate HttpRequest
    HttpRequest-->>MyImage: HttpRequestInstance
    deactivate HttpRequest

    MyImage->>HttpRequest: SendAsync(addMetedata: false)
    activate HttpRequest
    rect rgb(230,230,230)
        Note over HttpRequest: HTTP version negotiated by runtime
    end
    HttpRequest->>Server: HTTP request (HTTP2_or_HTTP3)
    Server-->>HttpRequest: HTTP response
    deactivate HttpRequest

    MyImage->>MyImage: EnsureSuccessStatusCode()
    MyImage->>MyImage: WriteTo FileStream(tempDownloadingPath)
Loading

File-Level Changes

Change Details Files
Stop forcing HTTP/3 when issuing HTTP requests for image downloads, allowing the runtime to select a compatible HTTP version and avoiding the QuicException-related crash path.
  • Removed explicit HTTP/3 version option from the HTTP request builder used in image download logic
  • Kept the existing download flow, response handling, and file I/O intact so behavior changes only in the selected HTTP protocol version
Plain Craft Launcher 2/Controls/MyImage.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#3226 Prevent the "未观测到的异步任务异常" (UnobservedTaskException) error that occurs with weak network conditions when paging through any tab in the '社区资源' (Community Resources) section (e.g., Mods) during downloads.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@SALTWOOD SALTWOOD requested a review from a team June 23, 2026 20:52

@sourcery-ai sourcery-ai 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.

Hey - 我在这里给出了一些高层次的反馈:

  • 建议将 HTTP 版本的配置进行集中管理(例如通过共享的 HttpRequest 工厂或配置对象),这样在禁用 HTTP/3 时就不需要修改每一个调用点,并且在升级到 .NET 10 后也可以轻松恢复。
  • 鉴于这只是一个临时缓解措施,建议在移除 WithHttpVersionOption(HttpVersion.Version30) 的位置附近加上一条简洁的代码注释,说明 .NET 8 运行时的相关 bug,以及计划在升级到 .NET 10 后重新评估这一改动,以方便后续维护者理解。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- Consider centralizing the HTTP version configuration (e.g., via a shared HttpRequest factory or settings object) so that disabling HTTP/3 doesn’t require touching each individual call site and can be easily reverted when upgrading to .NET 10.
- Given this is a temporary mitigation, it might be helpful to add a concise code comment near the removed `WithHttpVersionOption(HttpVersion.Version30)` describing the .NET 8 runtime bug and the intent to revisit this after upgrading to .NET 10, to aid future maintainers.

Sourcery 对开源项目是免费的——如果你觉得我们的 Review 有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的 Review。
Original comment in English

Hey - I've left some high level feedback:

  • Consider centralizing the HTTP version configuration (e.g., via a shared HttpRequest factory or settings object) so that disabling HTTP/3 doesn’t require touching each individual call site and can be easily reverted when upgrading to .NET 10.
  • Given this is a temporary mitigation, it might be helpful to add a concise code comment near the removed WithHttpVersionOption(HttpVersion.Version30) describing the .NET 8 runtime bug and the intent to revisit this after upgrading to .NET 10, to aid future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider centralizing the HTTP version configuration (e.g., via a shared HttpRequest factory or settings object) so that disabling HTTP/3 doesn’t require touching each individual call site and can be easily reverted when upgrading to .NET 10.
- Given this is a temporary mitigation, it might be helpful to add a concise code comment near the removed `WithHttpVersionOption(HttpVersion.Version30)` describing the .NET 8 runtime bug and the intent to revisit this after upgrading to .NET 10, to aid future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@pcl-ce-automation pcl-ce-automation Bot added 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 and removed 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 labels Jun 24, 2026

@RyogiMutsuki RyogiMutsuki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

其实最优解是利用 Polly 把 QuicException 包装为 HttpRequestException,这样不需要改动运行时版本就能获得几乎一致的行为

不过这样应该也没什么问题

@RyogiMutsuki RyogiMutsuki merged commit 7ec732f into dev Jun 24, 2026
3 checks passed
@pcl-ce-automation pcl-ce-automation Bot added 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 labels Jun 24, 2026
@RyogiMutsuki RyogiMutsuki deleted the fix/quic-exception branch June 24, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS PR 大小评估:微型 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C#]: 在网络信号弱时,“社区资源”栏中的一切选项卡在翻页时会有概率报错“未观测到的异步任务异常”

4 participants