fix(drivers): stop the upload retry loop when the context is canceled - #2892
Open
beardthelion wants to merge 1 commit into
Open
fix(drivers): stop the upload retry loop when the context is canceled#2892beardthelion wants to merge 1 commit into
beardthelion wants to merge 1 commit into
Conversation
The 115 and pikpak multipart uploaders checked for cancellation with a `case <-ctx.Done()` inside a select, and a break there only leaves the select, not the enclosing `for retry := 0; retry < 3; retry++` loop. Cancelling an upload therefore ran all three attempts for every remaining chunk, each allocating a chunk-sized buffer and reading it off disk before firing a request that could not succeed, and reported a transport error instead of the cancellation. Move the check ahead of the select and use utils.IsCanceled, matching the pattern the other drivers already use. Assigning ctx.Err() to err is load-bearing: without it a cancelled chunk takes the success branch, counts toward progress, and appends a zero-value UploadPart. Found with staticcheck (SA4011).
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.
Summary / 摘要
The 115 and pikpak multipart uploaders check for cancellation with
case <-ctx.Done()inside aselect, andbreakthere only leaves theselect, not the enclosingfor retry := 0; retry < 3; retry++loop. Cancelling an upload therefore did not stop the retry loop.The visible effect is wasted work rather than a stuck transfer.
RateLimitReader.ReadchecksCtx.Err()first (internal/stream/limit.go:43-46), so no part data actually goes out after a cancel. But every remaining chunk still runs all three attempts, each allocating achunk.Sizebuffer and reading that many bytes off disk before firing a request that cannot succeed, and each chunk then reports an OSS transport error instead of the cancellation.chunksProduceris not context aware, so this repeats for every chunk left in the channel, timesThreadsNumworkers.The fix moves the check ahead of the
selectand usesutils.IsCanceled, which is the pattern the other drivers already use for this (drivers/doubao/util.go,drivers/onedrive/util.go,drivers/189_tv/utils.go, and others). Assigningctx.Err()toerris load-bearing: without it a cancelled chunk falls through to the success branch, counts toward progress, and appends a zero-valueoss.UploadParttoparts.Scope is deliberately limited to the ineffective
break.chunksProducerstaying context unaware, and thecase <-errCh: return nil, errconsumer discarding the received value, are both pre-existing and left alone./ 此 PR 包含破坏性变更。
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
/ 此 PR 需要关联仓库同步修改。
Testing / 测试
Found with
staticcheck(SA4011), which flagged both sites and reports clean after the change:A full
staticcheck ./...andgo vet ./...before and after show no new findings, only those two removed.go build ./...andgofmtare clean.go test ./...was run. It is not fully green on940b69feeither:TestNewOSSClientUsesEnvironmentHTTPSProxyininternal/netfails identically before and after this change, and several drivers fail to build under vet for pre-existing non-constant format string errors. Neither driver touched here has tests, andUploadByMultipartneeds a live bucket, so there is no unit test to add without restructuring the upload path. I did not want to grow the diff for that. Happy to if you would prefer it.go test ./...Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 我已按适用情况使用
gofmt、go fmt或prettier格式化变更代码。AI Disclosure / AI 使用声明
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
Usage scope / 使用范围:
staticcheck surfaced the defect. AI assistance was used for the root cause investigation and the patch, and a second model from a different family reviewed the change independently. The reporter reviewed and validated the change before submission.