Skip to content

[BUG] 会话过期后并发请求可能覆盖新登录 Cookie,导致课程表加载失败 #701

Description

@w568w

描述 Bug

复旦会话过期后,如果多个请求并发访问需要统一身份认证的服务,应用可能在重新登录成功后仍保留无效 Session。此时课程表加载失败,并弹出 Authentication required for request 错误。

该问题具有并发时序相关性,不一定每次都能稳定复现。发生后,课程表页面无法正常显示;重复刷新也可能继续跳转到统一身份认证页面。

复现步骤
复现该 Bug 的步骤:

  1. 以本科生身份登录旦挞并正常使用复旦服务。
  2. 等待复旦 Session 过期,或在服务端 Session 已失效的状态下重新打开应用。
  3. 进入「日程」页面,触发课程表及其他复旦服务请求并发加载。
  4. 应用尝试自动重新认证。
  5. 部分情况下,课程表仍加载失败并显示认证错误。

课程表页面显示“加载失败”,错误信息类似:

ParallelWaitError: Exception:
Authentication required for request:
id.fudan.edu.cn/idp/authCenter/authenticate?service=...
/student/sso/login?refer=.../student/for-std/course-table

原因

当前各种请求流程(普通请求 和 登录请求)共用同一个 CookieJar。可能出现以下竞态:

  1. 请求 A 使用旧 Cookie 发出;
  2. 请求 B 发现认证失效并完成重新登录,把新 Cookie 写入共享 CookieJar;
  3. 请求 A 的旧响应这时才珊珊来迟,返回 Set-Cookie
  4. CookieManager 无法判断该响应属于登录前的旧会话,于是把旧 Cookie 再次写回共享 CookieJar;
  5. 新登录 Session 被覆盖,后续课程表请求再次被要求认证。

此外,登录过程直接操作共享 CookieJar 时,中途响应写入的 Cookie 也会立即影响其他并发请求;若登录失败,共享状态可能留下不完整的认证 Cookie。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Complexity: HighDifficult to trace the root cause, or requiring a thorough understanding of the entire projectbugSomething isn't workinghigh priorityIt should be worked on NOW

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions