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(getSession): use semaphore lock for unseal operation #612

Merged
merged 7 commits into from
Jan 15, 2024
Merged

fix(getSession): use semaphore lock for unseal operation #612

merged 7 commits into from
Jan 15, 2024

Conversation

JAD3N
Copy link
Contributor

@JAD3N JAD3N commented Jan 8, 2024

πŸ”— Linked issue

#610

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I've added session locking that will asynchronously block consecutive getSession attempts when unsealing.

This should solve the problem where consecutive getSession calls break session data and prevent duplicate unseals (I tested the changes against the issue's reproduction).

Resolves #610

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@JAD3N JAD3N changed the title Add Session Locking for Unseals fix: Add Session Locking for Unseals Jan 8, 2024
@pi0 pi0 changed the title fix: Add Session Locking for Unseals fix(session): use semaphore lock for unseal operation Jan 15, 2024
Copy link

codecov bot commented Jan 15, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Comparison is base (ba275c3) 77.69% compared to head (cfdacf3) 77.79%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
+ Coverage   77.69%   77.79%   +0.09%     
==========================================
  Files          47       47              
  Lines        4269     4279      +10     
  Branches      604      609       +5     
==========================================
+ Hits         3317     3329      +12     
+ Misses        935      933       -2     
  Partials       17       17              

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@pi0
Copy link
Member

pi0 commented Jan 15, 2024

Thanks for the PR ❀️ I have added tests and few refactors to simplify using same context.sessions for locking.

As a future enhancement, we need to do concurrency/promise-reuse in function level which is currently not possible as updateSession has dependency on getSession promise but it will likely catch other edge case scenarios. (~> #617)

@pi0 pi0 changed the title fix(session): use semaphore lock for unseal operation fix(getSession): use semaphore lock for unseal operation Jan 15, 2024
@pi0 pi0 merged commit 4475b74 into unjs:main Jan 15, 2024
6 checks passed
@JAD3N JAD3N deleted the fix-concurrent-sessions branch January 15, 2024 21:39
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.

Concurrent calls to getSession leads to only the first one getting the session
2 participants