-
Notifications
You must be signed in to change notification settings - Fork 634
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Handle reconnection for Sessions #134
Comments
So here's my brain dump about the whole reconnection thing. Currently one The alternative is to move to a model where a impl Session {
fn new(config: SessionConfig, cache: Option<Cache>, handle: Handle) -> Session { ... }
fn connect(&self, credentials: Credentials) -> impl Future<Credentials, ConnectionError> { ... }
} The Trying to use an unconnected session (to get metadata, audio key/data, etc...) should fail gracefully. All the APIs already use Future/Stream, so these just need to resolve into errors. Same happens if the connection is lost while a request is in flight. Player and Spirc need to behave correctly when those requests fail. For Player it just means returning to the NotPlaying state and signal the caller that playback has completed with an error. For Spirc, when Player signals a connection problem it should probably stop playback. Reading from or sending to the mercury channel may start failing as well. Now to get back up, I suggest the Session signals in some way to This can mean various things depending on the component. The components need to expose an API that looks like: impl Component {
fn connection_established(&self, username: String) { ... }
fn dispatch(&self, cmd: u8, mut data: Bytes) { ... }
fn connection_closed(&self) { ... }
} There are some risks of race conditions that need to be carefully though about. I think I have some initial implementation of this somewhere, I'll try and find it again. |
@plietar did you find that initial implementation anywhere? |
Regardless, I think we should be aiming to make this as simple to integrate as possible, as handling reconnection logic from whatever project uses librespot sounds like plenty of headache for anyone who tries to use librespot, whilst also being pretty low level functionality that I personally would expect to be handled in any library I used. Anyway, these are just my two cents since I'm not sufficently versed in rust to be able to rewrite how sessions are handled. Would be good to hear others thoughts as to how this should be handled. |
I am trying to wrap my head around this issue. AFAICS, the disconnect error starts at Since
So this works for the binary case. For the library case @plietar suggests to let main reconnect using last credentials and let Spirc, Player, etc. pick up the new session and reset its state accordingly. I have two problems trying to implement this
If you look at examples/play.rs you can do a match on |
Is there any way to mitigate this problem? |
This doesn't address the cause but aids with the symptoms: Script to be run as a cronjob every minute which checks the status and restarts the service if an error is spotted. |
Is the cronjob patch the best solution for this issue currently? Sometimes I'm 25 songs in, sometimes I'm 4 when I lose connection. This is running on a server connected directly to my modem/router via ethernet. I can't imagine it's actually losing internet connection this consistently. |
Sounds like this is closely related to, and would probably help solve #266 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
This issue serves as a placeholder for discussion around the rewrite of the session handling logic, as it is currently one of the less stable parts of librespot. Issue #103 is related to this.
The text was updated successfully, but these errors were encountered: