Skip to content

fix(filesystem): dedupe concurrent initial auth requests#1437

Merged
CodFrm merged 1 commit into
mainfrom
fix/sync/016
May 15, 2026
Merged

fix(filesystem): dedupe concurrent initial auth requests#1437
CodFrm merged 1 commit into
mainfrom
fix/sync/016

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

概要

修复首次授权场景下,并发调用 AuthVerify() 时会重复触发授权流程的问题。

当本地不存在 token 或 token 缺少 accessToken 时,同一网盘类型的多个并发认证请求现在会复用同一个授权 Promise,避免重复打开授权页、重复请求 token、重复写入本地存储。

主要改动

  • 新增 authTokenPromises,按网盘类型缓存首次授权中的 Promise
  • 并发 AuthVerify(netDiskType) 在缺少 token 时复用同一次授权请求
  • 授权成功后只保存一次 token
  • 授权流程结束后清理对应的 pending Promise,避免影响后续认证
  • 保留原有 refresh token 并发去重逻辑不变

修复的问题

在多个同步任务或多个文件系统操作几乎同时触发认证时,如果当前没有可用 token,之前每个请求都会各自执行:

  • 打开授权页
  • 请求 GetNetDiskToken
  • 写入 token 到本地存储

这可能导致用户看到多个授权窗口,或者产生重复 token 请求。

本 PR 修复后,同一网盘类型的首次授权流程只会执行一次,其他并发请求等待同一个结果。

测试

新增单元测试覆盖:

  • 并发首次认证时只打开一次授权页
  • 只请求一次 token
  • 只保存一次 token
  • 所有并发调用都返回同一个 access token

@cyfung1031 cyfung1031 mentioned this pull request May 11, 2026
Closed
@cyfung1031 cyfung1031 added the CloudSync Related to CloudSync label May 11, 2026
@CodFrm CodFrm requested a review from Copilot May 15, 2026 05:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

修复并发首次授权时重复触发授权流程的问题。通过为每个网盘类型缓存进行中的授权 Promise,使并发的 AuthVerify 调用复用同一次授权过程,避免重复打开授权页、重复请求 token 与重复写入本地存储。

Changes:

  • 新增 authTokenPromises 缓存按 NetDiskType 去重的首次授权 Promise
  • AuthVerify 在缺少 token 时复用同一个进行中的授权 Promise,保存 token 仅执行一次
  • 新增并发首次授权的单元测试覆盖

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/filesystem/auth.ts 引入 authTokenPromises 去重缓存,将首次授权流程封装为单个共享 Promise 并在结束时清理
packages/filesystem/auth.test.ts 新增并发首次授权的测试,验证仅打开一次授权页、仅请求一次 token、仅保存一次

@CodFrm CodFrm merged commit ee5b80d into main May 15, 2026
8 checks passed
@CodFrm CodFrm deleted the fix/sync/016 branch May 15, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CloudSync Related to CloudSync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants