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

core: retry session connection #1345

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

kingosticks
Copy link
Contributor

@kingosticks kingosticks commented Sep 19, 2024

When session connection fails, retry the access point. If still fails for a non-auth-login reason, repeat for the other access points. Also some logging tweaks.

When blocking ap-gew1.spotify.com, now I see each a retry for each AP on that host, until it finds an AP on a different host and succeeds.

[2024-09-20T22:41:44Z DEBUG librespot_core::http_client] Requesting https://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient
[2024-09-20T22:41:44Z INFO  librespot_core::session] Connecting to AP "ap-gew1.spotify.com:4070"
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Retry access point...
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z WARN  librespot_core::session] Try another access point...
[2024-09-20T22:41:44Z INFO  librespot_core::session] Connecting to AP "ap-gew1.spotify.com:443"
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Retry access point...
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z WARN  librespot_core::session] Try another access point...
[2024-09-20T22:41:44Z INFO  librespot_core::session] Connecting to AP "ap-gew1.spotify.com:80"
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Retry access point...
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Connection failed: Connection refused (os error 111)
[2024-09-20T22:41:44Z WARN  librespot_core::session] Try another access point...
[2024-09-20T22:41:44Z INFO  librespot_core::session] Connecting to AP "ap-guc3.spotify.com:4070"
[2024-09-20T22:41:44Z DEBUG librespot_core::connection] Authenticating with AP using AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS
[2024-09-20T22:41:45Z INFO  librespot_core::session] Authenticated as 'XXX' !

When using bad credentials, it does not retry:

[2024-09-20T23:12:15Z DEBUG librespot_core::http_client] Requesting https://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient
[2024-09-20T23:12:15Z INFO  librespot_core::session] Connecting to AP "ap-gew1.spotify.com:4070"
[2024-09-20T23:12:15Z DEBUG librespot_core::connection] Authenticating with AP using AUTHENTICATION_SPOTIFY_TOKEN
[2024-09-20T23:12:15Z ERROR librespot] could not initialize spirc: Permission denied { Login failed with reason: Bad credentials }

@kingosticks kingosticks marked this pull request as draft September 20, 2024 00:09
core/src/session.rs Outdated Show resolved Hide resolved
core/src/session.rs Outdated Show resolved Hide resolved
@kingosticks kingosticks force-pushed the session-retry-connect branch 2 times, most recently from 3cbef8f to 59a254b Compare September 20, 2024 23:04
@kingosticks kingosticks marked this pull request as ready for review September 20, 2024 23:14
@kingosticks
Copy link
Contributor Author

@michaelherger I re-implemented this after realising it was retrying even when the auth failed due to a bad login, and it was also looping around the access points forever.

Tries multiple access-points with a retry for each one, unless was
a login failure.
@michaelherger
Copy link
Contributor

I'm away for the weekend... with limited internet access. I'll look into this ASAP. Thanks a ton!

Copy link
Contributor

@michaelherger michaelherger left a comment

Choose a reason for hiding this comment

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

My Rust is very limited... I probably learned more from that PR than I knew before 🤦🏻.

But given my limited understanding I believe the change makes sense. See inline comments for some validation of my assumptions. Thanks!

core/src/session.rs Show resolved Hide resolved
core/src/session.rs Show resolved Hide resolved
@michaelherger
Copy link
Contributor

...and testing the code I'm already seeing a first "Connection refused" event fixed by this patch. 👍🏻

@roderickvd
Copy link
Member

So, good to merge?

Depending on the discussion with login5, this could be a good last one to get in before v0.5. I feel like Spotify's infra error was good fortune, so people switched to dev and gave it a good shakedown.

@michaelherger
Copy link
Contributor

So, good to merge?

If @kingosticks can confirm my assumptions, then I'd be happy to have this merged! It clearly improves behaviour for my use case.

Depending on the discussion with login5, this could be a good last one to get in before v0.5. I feel like Spotify's infra error was good fortune, so people switched to dev and gave it a good shakedown.

I feel caught out 😁.

@michaelherger
Copy link
Contributor

FWIW: I've now played about 70 tracks without hiccup, for which librespot needed to re-try three times. Great job!

Copy link
Contributor

@michaelherger michaelherger left a comment

Choose a reason for hiding this comment

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

Thanks for the clarifications!

IMHO good to merge.

@roderickvd roderickvd merged commit e02e4ae into librespot-org:dev Sep 23, 2024
13 checks passed
@kingosticks kingosticks deleted the session-retry-connect branch September 23, 2024 19:34
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