refactor(client): use context.WithTimeout for upload timeout#13
Merged
Conversation
…ing httpClient Replace the pattern of temporarily swapping httpClient.Timeout (not concurrency-safe) with context.WithTimeout on the request. This is the idiomatic Go approach and safe for concurrent use.
…patible impl multipart.FileContentDisposition was introduced in Go 1.25 but go.mod targets 1.24, causing CI build failures. Replace with manual Content-Disposition header construction with proper quote escaping.
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.
跟进 #11 的上传超时修复,把临时修改 httpClient.Timeout 的方式改为 context.WithTimeout。
问题: 直接修改
c.httpClient.Timeout再恢复不是并发安全的——如果有多个 goroutine 共用同一个 Client,会 data race。改法: 用
context.WithTimeout+req.WithContext(ctx),这是 Go 的惯用方式,per-request 粒度,不影响其他请求。改动量: 4 行替换 4 行,行为不变。