Skip to content

fix: add context timeout for passport login request - #382

Merged
raiki02 merged 1 commit into
mainfrom
fix/retryLogin
Sep 8, 2026
Merged

raiki02 merged 1 commit into
mainfrom
fix/retryLogin

Conversation

@raiki02

@raiki02 raiki02 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@bingling-sama

Copy link
Copy Markdown
Contributor

loginCCNUPassport 爬虫函数在发送 http 请求时使用了业务上下文,导致首次 http 请求失败时 ctx 被取消,Retry 无法进行

@raiki02
raiki02 merged commit 3c64c55 into main Sep 8, 2026
13 checks passed
@raiki02
raiki02 deleted the fix/retryLogin branch September 8, 2026 01:17
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

登录 POST 请求现在使用基于 context.Background() 的独立 1 秒超时上下文。函数返回时会调用取消函数。该请求不再继承调用方上下文。

未发现关键问题。

Merge Risk: 🟡 Moderate · up to 1afd5

登录请求虽然增加了 1 秒超时,但会忽略调用方取消和更早的截止时间,导致已取消的登录仍继续执行;合并前应改为从调用方上下文派生超时。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive 未提供拉取请求描述。现有信息不足以判断请求的背景、影响范围或验证方式。 补充拉取请求描述,说明 1 秒超时上下文的目的、对登录请求行为的影响,以及已执行的测试或验证步骤。
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确说明了为护照登录请求增加上下文超时的主要变更,内容简洁且与代码改动一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/retryLogin

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 0d589fb6-f5e1-407e-866c-c1c92eba6445

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6cd6a and 1afd5a8.

📒 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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-ccnu

Repository: asynccnu/ccnubox-be

Length of output: 14915


让登录请求继承调用方的 ctx

loginCCNUPassport 接收了 LoginPassportctx,但在第 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

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.

2 participants