Skip to content

fix(drivers/115): handle multipart upload failures safely - #3312

Open
Suyunmeng wants to merge 5 commits into
mainfrom
fix/3201-115-multipart-error
Open

Suyunmeng wants to merge 5 commits into
mainfrom
fix/3201-115-multipart-error

Conversation

@Suyunmeng

@Suyunmeng Suyunmeng commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 摘要

  • 修复 115 分片上传丢失真实错误的问题,避免上传失败时返回 nil 结果并触发后续空指针崩溃。
    Fix lost errors in 115 multipart uploads to prevent nil results and downstream nil-pointer panics.

  • 改进 WebDAV 上传失败的 HTTP 状态码映射:权限错误返回 403,不支持上传返回 405,其他后端失败返回 500。
    Improve WebDAV upload error mapping: permission failures return 403, unsupported uploads return 405, and other backend failures return 500.

  • 完善 multipart worker、channel、context 和 OSS multipart session 的生命周期清理。
    Clean up multipart worker, channel, context, and OSS multipart-session lifecycles.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。

  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。

  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend:
  • OpenList-Docs:

Related Issues / 关联 Issue

Fixes #3201

Testing / 测试

  • go test ./...
  • Targeted tests / 目标测试: go test ./drivers/115 ./server/webdav
  • gofmt and git diff --check
  • Manual test / 手动测试: 未使用真实 115 账号和 OSS 环境进行手动上传测试。

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmt、go fmt 或 prettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明): Lunelle ( Experimental AI )

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Documentation / 文档

  • Tests / 测试

  • Translation / 翻译

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.
    / 我已审核并验证此 PR 中的所有 AI 辅助内容。

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的 AI 辅助内容。

Suyunmeng and others added 3 commits October 27, 2026 23:51
- Return the error received from the multipart upload error channel.
- Prevent successful nil results from reaching the upload result dereference.

Co-authored-by: LunelleEverdawn <lunelle+suyunmeng@oplist.org>
- Map permission failures to 403 and unsupported uploads to 405.
- Return 500 for other backend upload failures instead of 405.

Co-authored-by: LunelleEverdawn <lunelle+suyunmeng@oplist.org>
- Cancel multipart workers on upload failures and timeout.
- Close upload channels after workers exit and abort failed uploads.

Co-authored-by: LunelleEverdawn <lunelle+suyunmeng@oplist.org>
@Suyunmeng
Suyunmeng requested a review from a team October 27, 2026 21:50
@xrgzs
xrgzs requested a lite review from Copilot October 28, 2026 02:14
@xrgzs xrgzs changed the title fix(115): handle multipart upload failures safely fix(drivers/115): handle multipart upload failures safely Oct 28, 2026

Copilot AI 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.

🟡 Changes recommended

Two unresolved moderate issues remain: WebDAV upload errors for unimplemented or unsupported drivers now return 500 instead of 405, and the 115 upload path can discard a real chunk error when token refresh also fails.

2 open issues
What changed in this PR

This PR fixes a 115 driver bug where a multipart upload failure could return a nil result and cause a nil-pointer panic. It also changes how WebDAV maps upload errors to HTTP status codes. The 115 fix addresses issue #3201.

Changes:

  • Rewrites the 115 multipart upload flow to use a cancellable context, report the first real error, abort the OSS multipart session on failure, and wait for workers to finish.
  • Maps WebDAV PUT errors to 403 for permission failures, 405 for unsupported uploads, and 500 for other backend failures.
File Description
server/​webdav/​webdav.go Maps upload errors to 403, 405, or 500 instead of always returning 405.
drivers/​115/​util.go Propagates real chunk errors, cancels workers on failure, and aborts the OSS multipart session.

Review effort: Lite

Comment thread drivers/115/util.go Resolved
Comment thread server/webdav/webdav.go Resolved

@jyxjjj jyxjjj 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.

[P2] 不支持上传的错误没有覆盖完整,部分原本返回 405 的情况会变成 500。

server/webdav/webdav.go:538

这里只匹配 UploadNotSupported,但 op.Put 在驱动没有实现 Put 时返回 NotImplement,一些驱动的 Put 也直接返回 NotSupport。它们现在都会落到 500,和这次保留“不支持上传返回 405”的目标不一致。

要把 NotImplement、NotSupport 一起映射到 405,并覆盖这些错误经过包装后的情况。

[P2] 刷新 token 失败时仍然可能丢掉已经上报的分片错误。

drivers/115/util.go:437

主循环进入 GetOSSToken 后,worker 可能先把分片错误写入 errCh 并取消上传。如果 GetOSSToken 随后也失败,这里会直接返回 tokenErr,没有读取已经排队的分片错误,原始上传失败原因就被覆盖了。

要和 timeout 分支一样,优先取 errCh 中已经上报的错误,没有时再使用 tokenErr。


Generated by ChatGPT-6.1-Sol Medium

- Map unimplemented and unsupported driver uploads to HTTP 405.
- Prefer queued chunk errors over OSS token refresh failures.

Co-authored-by: LunelleEverdawn <lunelle+suyunmeng@oplist.org>
@Suyunmeng
Suyunmeng requested a review from jyxjjj October 28, 2026 14:03

@jyxjjj jyxjjj 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.

[P2] 两处取消分片上传的请求没有带 SecurityToken,OSS 清理会失败。

drivers/115/util.go:473、489

这里创建 OSS 客户端时只传了 AccessKeyID 和 AccessKeySecret,没有全局配置 SecurityToken。初始化、上传分片和完成上传都通过请求选项单独传 token,但新增的 AbortMultipartUpload 只传了 context。SDK 的取消上传实现也不会替调用方补上这个 token。

因此取消、超时、分片失败或完成请求失败后,清理请求会缺少临时凭据中的 SecurityToken。返回错误又被忽略,OSS multipart session 和已上传分片会留下。

两处 AbortMultipartUpload 都要带上对应的 SecurityToken。

之前指出的 token 刷新失败覆盖分片错误,以及 WebDAV 不支持上传错误被映射为 500 的问题,最新修改已经处理。


Reviewed or refined by GPT-6.1-Sol Medium

- Pass the current OSS security token to both multipart abort requests.

Co-authored-by: LunelleEverdawn <lunelle+suyunmeng@oplist.org>
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] 115 驱动分片上传丢弃 errCh 真实错误,导致 nil 指针 panic / WebDAV 405

3 participants