-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Refresh fixes #263
Refresh fixes #263
Conversation
Just wanted to say thanks for continuing this work! Just updated a small project of mine and I'm so happy caching and auto refresh works (haven't tried the auto refresh just yet, but caching does work). ❤️ Noticed the stack overflow issue and then I saw you fixed it 5 minutes before I saw it. 😅 |
@AndreasBackx thanks a bunch! These messages are really encouraging :) I'm really proud of how the interface of rspotify has turned out to be. If you have any issues let us know! I think we'll release the new version very soon, probably ignoring #221 for now. |
@marioortizmanero Thanks for your contribution, you have done such tons of brilliant improvement |
|
||
handles.push(handle); | ||
} | ||
drop(wr); // Automatically closed channel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to close write channel by calling drop
explicitly? It seems wr
will be dropped automatically when it goes out of scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try removing it and see how it never ends. The thing is that we have a write channel per task/thread, and then also the original one in the main function, which we cloned and passed to the tasks/threads. Since the loop (which is in the main function) waits until all write channels have been dropped, if we don't manually drop the one in main it will never end.
Another way to do it would be with a function or scoping, but I figured this was simple enough.
|
||
// NOTE: It's important to not leave the token locked, or else a | ||
// deadlock when calling `refresh_token` will occur. | ||
let should_reauth = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the thing is that in should_reauth the lock is dropped after turning it into a boolean because it's a single statement. If it was a two step process and we fist locked the mutex in a separate variable and then checked should_reauth, then we'd have a problem because the mutex is still in scope. This is kinda what happened before. We had an if let statement that checked the value of the mutex, and inside that we accessed the mutex again. But by then the mutex hadn't been dropped. Actually, the previous way of doing it might work as well because since we're matching against the token in the if let we don't really have the mutex in scope anymore. But I think this leaves it clearer that there's no mutex anymore. |
This sounds like a temporary value doesn't live long enough. You did a great job |
Description
Some fixes for #262:
examples/with_auto_reauth.rs
exampleauto_reauth
andrefresh_token
to the trait, since we already haverefetch_token
available.auto_reauth
is only called once, and we can avoid having two token getters (one that refreshes and another that doesn't).Token::is_expired
now includes a margin of 10 secondsToken::can_reauth
was wrong: it checked ifrefresh_token
wasSome()
, but that's not true in the case of client credentials.Motivation and Context
See #262
Dependencies
None
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
You can run the new test with: