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

bugfix: refresh before token expires, not after #254

Merged
merged 3 commits into from
Nov 24, 2023

Conversation

timbertson
Copy link
Contributor

If you set refreshBeforeExpiration to 1 minute, the current code refreshes the token only after the token has expired for at least a minute. Time maths are hard, I had to add the test to actually verify my hunch 😆

@joan38
Copy link
Owner

joan38 commented Nov 15, 2023

./mill __.style, push the style fix and we should be good to go.
Thanks!

@timbertson
Copy link
Contributor Author

Done 👍

@yurique
Copy link
Collaborator

yurique commented Nov 15, 2023

Oh interesting 🤔
What a nasty bug and a nice catch!

It indeed looks like a plusSeconds vs minusSeconds problem here:

val shouldRenew =  cached.expirationTimestamp.exists(_.isBefore(now.minusSeconds(refreshBeforeExpiration.toSeconds)))
                                                                     ~~~~~~~~ 

it should be like this (with .plusSeconds), right? (time maths are hard :) )


don't refresh
TIME ----------|-----------|-----------------------------|--------------->
               \ now       \ now+                        \ token
                             refreshBefore                 expiration
                                 \------------------------NOT isBefore

do refresh
TIME ----------|-----------|----------------------------|--------------->
               \ now       \ token                      \ now+                        
                             expiration                   refreshBefore 
                                 isBefore---------------------/


do refresh
TIME ---------|---------------------|-------------------|--------------->
              \ token               \ now               \ now+                        
                expiration                                refreshBefore 
                   isBefore---------------------------------/ 

@timbertson
Copy link
Contributor Author

timbertson commented Nov 24, 2023 via email

@joan38 joan38 merged commit 970a738 into joan38:main Nov 24, 2023
7 checks passed
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