Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unpkg lock #629

Merged
merged 1 commit into from
Dec 25, 2023
Merged

fix: unpkg lock #629

merged 1 commit into from
Dec 25, 2023

Conversation

elrrrrrrr
Copy link
Member

When accessing the unpkg service, when the packages have not yet been synchronized, will lead to multiple synchronization attempts concurrently causing db insert errors.

  • 🔒 Added a Redis lock for the ensurePackageVersionFilesSync function, with a default timeout of 60 seconds.
  • 🥸 Admin PUT requests and the package version auto sync process are not restricted by this.

当访问 unpkg 服务时,如果访问存量未同步的包,可能导致多次同步并发报错

  • 🔒 为 ensurePackageVersionFilesSync 添加 redis 锁,默认超时 60s
  • 🥸 管理员手动 PUT 请求和包同步流程不受限制

@elrrrrrrr elrrrrrrr added the bug Something isn't working label Dec 24, 2023
@elrrrrrrr elrrrrrrr requested review from fengmk2 and killagu December 24, 2023 15:19
Copy link

codecov bot commented Dec 24, 2023

Codecov Report

Attention: 166 lines in your changes are missing coverage. Please review.

Comparison is base (6624a36) 97.45% compared to head (f4d416c) 96.85%.
Report is 151 commits behind head on master.

Files Patch % Lines
config/config.default.ts 56.33% 31 Missing ⚠️
.../port/controller/admin/PaddingVersionController.ts 48.83% 22 Missing ⚠️
app/core/service/FixNoPaddingVersionService.ts 54.54% 15 Missing ⚠️
app/core/service/PackageSearchService.ts 93.72% 15 Missing ⚠️
app/core/service/PackageSyncerService.ts 85.84% 15 Missing ⚠️
app/port/schedule/SyncBinaryWorker.ts 21.42% 11 Missing ⚠️
app/repository/PackageVersionRepository.ts 87.95% 10 Missing ⚠️
app/core/service/PackageVersionFileService.ts 92.59% 8 Missing ⚠️
app/core/entity/PaddingSemVer.ts 88.00% 6 Missing ⚠️
app/core/service/PackageVersionService.ts 94.91% 6 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #629      +/-   ##
==========================================
- Coverage   97.45%   96.85%   -0.60%     
==========================================
  Files         168      180      +12     
  Lines       15691    17567    +1876     
  Branches     2018     2290     +272     
==========================================
+ Hits        15291    17014    +1723     
- Misses        400      553     +153     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -50,8 +54,16 @@ export class PackageVersionFileService extends AbstractService {
async #ensurePackageVersionFilesSync(pkgVersion: PackageVersion) {
const hasFiles = await this.packageVersionFileRepository.hasPackageVersionFiles(pkgVersion.packageVersionId);
if (!hasFiles) {
await this.syncPackageVersionFiles(pkgVersion);
const lockRes = await this.cacheAdapter.usingLock(`${pkgVersion.packageVersionId}:syncFiles`, 60, async () => {
Copy link
Member

Choose a reason for hiding this comment

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

哈哈,这个 api 设计没有 tryLock 那个好。

@fengmk2 fengmk2 merged commit 5a8a4eb into master Dec 25, 2023
11 of 13 checks passed
@fengmk2 fengmk2 deleted the unpkg-lock branch December 25, 2023 03:05
fengmk2 pushed a commit that referenced this pull request Dec 25, 2023
[skip ci]

## [3.49.3](v3.49.2...v3.49.3) (2023-12-25)

### Bug Fixes

* unpkg lock ([#629](#629)) ([5a8a4eb](5a8a4eb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants