Skip to content

refactor(client): use context.WithTimeout for upload timeout#13

Merged
4ier merged 2 commits intomainfrom
fix/upload-timeout-context
Mar 20, 2026
Merged

refactor(client): use context.WithTimeout for upload timeout#13
4ier merged 2 commits intomainfrom
fix/upload-timeout-context

Conversation

@4ier
Copy link
Owner

@4ier 4ier commented Mar 20, 2026

跟进 #11 的上传超时修复,把临时修改 httpClient.Timeout 的方式改为 context.WithTimeout。

问题: 直接修改 c.httpClient.Timeout 再恢复不是并发安全的——如果有多个 goroutine 共用同一个 Client,会 data race。

改法: 用 context.WithTimeout + req.WithContext(ctx),这是 Go 的惯用方式,per-request 粒度,不影响其他请求。

改动量: 4 行替换 4 行,行为不变。

…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.
@4ier 4ier merged commit b66ed74 into main Mar 20, 2026
4 checks passed
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