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

WP-190: Client Token Mutex #856

Closed
wants to merge 1 commit into from

Conversation

happycodemonkey
Copy link
Member

Overview

Attempting to add a threading lock to the client refresh token code so that it doesn't keep trying to refresh the token on new threads.

Related

Changes

Added a small bit of code to (hopefully) lock the refresh_token function so that it is only called once.

Testing

I have no idea how to test this, definitely need to do some stress testing in dev or something before full deploy.

UI

Notes

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #856 (fb78bbf) into main (7920857) will decrease coverage by 0.02%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #856      +/-   ##
==========================================
- Coverage   63.05%   63.03%   -0.02%     
==========================================
  Files         427      427              
  Lines       12131    12136       +5     
  Branches     2481     2482       +1     
==========================================
+ Hits         7649     7650       +1     
- Misses       4278     4282       +4     
  Partials      204      204              
Flag Coverage Δ
javascript 68.84% <ø> (ø)
unittests 57.28% <16.66%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage
server/portal/apps/auth/models.py 16.66%

@@ -81,7 +82,11 @@ def client(self):
with transaction.atomic():
if self.expired:
try:
client.refresh_tokens()
lock = Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

creating a lock object within this client function will not achieve mutual exclusion. A new lock object is created always and two threads are not looking at same lock anymore.

The lock = Lock() needs to be created at class level.

@rstijerina
Copy link
Member

Closing in favor of #882

@rstijerina rstijerina closed this Oct 18, 2023
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.

3 participants