librespot-org / librespot

Open Source Spotify client library
MIT License
4.48k stars 542 forks source link

discovery::server: fix activeUser field of getInfo #1235

Open dsheets opened 6 months ago

dsheets commented 6 months ago

The current active user was almost persisted and reported but wasn't. The handler for the discovery server is under an Arc so I introduced a Mutex to protect the username field and made setting the username and sending the credentials atomic so that every valid credential send corresponds to an active user update.

There doesn't appear currently to be any way for this activeUser field to be reset back to the empty string when a user disconnects so one could argue that it's actually more broken now than before as it will keep reporting the last user to connect indefinitely instead of the user with a currently active session.

If you're interested in this fix, I may take a look at clearing the value in the future.

This issue was reported by @TimotheeGerber in https://github.com/TimotheeGerber/spotify-connect/pull/4#discussion_r1428834453.

roderickvd commented 6 months ago

Thanks! Yes this is a known shortcoming, nice to see something being done about it.

If you're interested in this fix, I may take a look at clearing the value in the future.

That would be nice. Do you want to handle that under this PR or a separate one?

roderickvd commented 6 months ago

bump you think you can take a shot at updating the user on disconnect / reconnect?

dsheets commented 6 months ago

Hi, sorry for the delay. I might have some time to take a look at this next week.

Finomnis commented 5 months ago

Don't use async Mutexes for short-lived locks like this. Use a normal std mutex instead. See this section of the tokio book for more information.

roderickvd commented 3 months ago

bump @Finomnis is right. Could you change it accordingly?