fix: add context timeout for passport login request - #382
Conversation
|
loginCCNUPassport 爬虫函数在发送 http 请求时使用了业务上下文,导致首次 http 请求失败时 ctx 被取消,Retry 无法进行 |
📝 WalkthroughWalkthrough登录 POST 请求现在使用基于 未发现关键问题。 Merge Risk: 🟡 Moderate · up to 登录请求虽然增加了 1 秒超时,但会忽略调用方取消和更早的截止时间,导致已取消的登录仍继续执行;合并前应改为从调用方上下文派生超时。 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Team
Run ID: 0d589fb6-f5e1-407e-866c-c1c92eba6445
📒 Files selected for processing (1)
be-ccnu/crawler/passport.go
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.
| v.Set("epid", "Edge145.0.0.0") | ||
| v.Set("ugt", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0") | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '110,165p' be-ccnu/crawler/passport.go
printf '\n--- callers and tests ---\n'
rg -n -C 4 'loginCCNUPassport|LoginPassport|NewRequestWithContext|WithTimeout' be-ccnuRepository: asynccnu/ccnubox-be
Length of output: 14915
让登录请求继承调用方的 ctx。
loginCCNUPassport 接收了 LoginPassport 的 ctx,但在第 139 行使用 context.Background() 创建超时上下文。调用方取消或客户端断开后,CAS 登录 POST 仍可能继续执行最多 1 秒。
请改用 context.WithTimeout(ctx, time.Second),并将派生上下文传给 http.NewRequestWithContext。同时增加父上下文取消期间的回归测试。
🧰 Tools
🪛 golangci-lint (2.13.2)
[error] 139-139: SA4009(related information): assignment to ctx
(staticcheck)
Source: Linters/SAST tools
No description provided.