-
Notifications
You must be signed in to change notification settings - Fork 452
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
use async/await for mainloop #1059
Conversation
Cheers mate, I do not know enough rust to be able to review, but going through doesn't seem like there's something to steal my credentials ;) I guess I just do:
yeah? |
Yeah, you should be fine just running this. If you need any of the features that are not enabled by default, here would be how to do that. And you can always turn on Hope it works for you! |
This comment was marked as resolved.
This comment was marked as resolved.
nvm I'm dumb, I didnt realize I still have to manually check out your branch (quite embarassing)... It works great for the zeroconf! Launch logs:
Netstat:
However, I had to change my backend to Running
|
Great to hear that it works for you! As for pulseaudio, you should be able to build via |
Awesome, this MR gets a 👍 from me!! |
looks very cool! dont have time right now, but ill review later |
This CI failure seems unrelated (probably a random networking issue). Although apparently the Edit: apparently the |
497c0cb
to
eb9eaff
Compare
I rebased this on the current master and CI is fine now (thanks for merging #1062 that quickly!). |
Seems like we have merge conflicts here now. |
Previously, handling too many librespot events in a row, the spawned hook might not have been finished. In this case, the events would stack up, since the event channel then would not be polled. By using the tokio::process module, we gain support for waiting for processes asynchronously and even if an event would not be handled directly, it will be handled after the previous hook process has finished.
The mainloop code is simplified by relying on the async / await syntax instead of implementing all the futures ourselves. In doing so, this also works, if a different user connects during the playback. Additionally, the application chooses now between connecting using the users credentials and starting discovery. If there are valid credentials, no discovery stream is started at all, which prevents buggy and surprising behaviour.
Also remove an unneeded clone.
Co-authored-by: Robin van Dijk <robin@robinjint.nl>
36241e1
to
de5c92e
Compare
I rebased this on top of current master and all merge conflicts should be resolved now. Note however that this still depends on changes in #1047 and that PR should probably go first (except if you just want to merge both at once, of course). |
Hey @eladyn, thank you for the nice PR, I (as a pure user) was really hoping for a fix for #1057. Something that I noticed though is that (when running this PR, or more precisely 3b7ee18 from your pr_collection branch) I often receive stale connections. I'm running spotifyd on a laptop, and usually after suspend I have to manually restart spotifyd because the playbackdevice offered via spotifyd is no longer visible. Verbose logging shows no activity after resuming from suspend. I guess that due to the hanging/now timeouted TCP-session, a reconnection has to be made. I'm not sure that this is actually a new problem, but may very well just now be as clearly visible (because before, due to the mDNS-advertisment there was a second communication vector that could make spotifyd initiate a new connection to spotify's servers). The issue should probably also be no blocker to this particular PR. I don't really know how to properly fix this past sending manual heartbeats to check that the connection is still valid... |
@noctux now that you mention it, I have also faced this issue. After a while of idling, my phone will no longer show the daemon. I kinda shrugged it off and just restarted spotifyd, but I guess it may be the heartbeat thing you mentioned as well. |
@noctux @ckcr4lyf The missing reconnection logic is definitely a long standing problem (see e.g. #903). Unfortunately, I don't think that there is anything we can do about that on the I agree that using this PR with an authorized user (and thus not with the zeroconf auth) makes this error more problematic, since it is no longer possible to recover from it. However, previously after a connection problem, you would have had to be on the same network to reconnect to the device. (Otherwise it would not be visible in the devices list.) With this PR, if you are on the same network, there is not much benefit from using user authentication anyway and you can just use zeroconf auth like before. If you are on a different network, the situation is the same as before: You can't trigger a reconnect, since the device does not appear in the list. So I would argue that this PR does not change the (admittedly annoying) situation much. Thanks for the feedback nonetheless! |
@eladyn Thanks for the pointers and your work. As I said I don't think that this should in any way influence the acceptance of this PR :D And from an privacy/security point of view this PR is a definitive win. I just wanted to document it here, in case other people search for it or you weren't aware of it. No worries :D And I can probably always restart it manually is music does not start playing |
Actually today after idling for couple of hours, was still able to connect to it. But anyway yeah that might be a deeper issue, the security benefit is much more important to me |
Bump, would be nice to have this merged in (currently am using this fork as my main) |
Adding to the reconnect issue: Actually, at times this code does detect that my laptop was in suspend:
After that, the device is not available as a sink, neither in the webplayer nor in other frontends such as spotify-qt or spotify-tui. I'm not sure if "relogin" needs a device-reregistering step there. (Edit: and no further output by spotifyd happens after that point) |
This works around the issue, where dbus servers would stay around until the application ends, although their corresponding session had already ended. New sessions were then unable to communicate through dbus. Now, newer servers will just replace any previous name owners.
As outlined in #1079 (comment), I noticed that the new possibility of re-using If you have different suggestions, please let me know. I hope that this was the last change that needs to be made and that this PR is finally ready to be merged. Thank you for your time! |
Thanks a lot for this work! It looks good to me, and I have merged. I will go through some other open PRs and see if I can put together a (long overdue) release. |
Another PR by me! 😅
This builds on top of #1047 (the first 4 commits are from that PR) and reimplements the mainloop using the
async
/await
syntax instead of implementing the futures and the polling all manually. While doing that, I also added the small fix from #1041. This turns the quite compleximpl Future
for theMainLoopState
into something more linear and readable (at least I hope so).My original motivation for this PR was to implement a config flag that would allow the user to disable the zeroconf discovery (#1057). While I was doing that, I realized that it'd make much more sense to decide automatically, wether we should use discovery or not. Thus, this PR implements the following behaviour:
By doing so, we basically get #1057 for free, since we either run as a bare Spotify Connect device that is open to everyone or as a playback device that is bound to one user. Note: This does not resolve the current issues with credentials caching (#1019, #948).
Another issue that is (as far as I can tell) resolved with this PR is
spotifyd
exiting on subsequent connections from different users.closes #1041
fixes #1057, fixes #1036,