fix(client): record a watch before the server can answer it
watch_user sent the request and only then recorded the watch. The server's answer is applied on the ops thread, so a reply that got there first saw nothing to drop for a user who does not exist, and the add that followed left that user watched for good. The lock is now taken before the send and held until the watch is recorded, so the answer always lands on it; a send that fails still records nothing.
This commit is contained in:
@@ -150,8 +150,11 @@ impl Client {
|
||||
/// Returns [`SoulseekRs::NotConnected`] if the client is not connected.
|
||||
pub fn watch_user(&self, username: &str) -> Result<()> {
|
||||
use crate::message::server::MessageFactory;
|
||||
// Held across the send: the reply is applied under this lock, so it
|
||||
// cannot land first and have its "does not exist" undone by the add.
|
||||
let mut context = self.context.write_safe()?;
|
||||
self.send_server_message(MessageFactory::build_watch_user(username))?;
|
||||
self.context.write_safe()?.add_watched_user(username);
|
||||
context.add_watched_user(username);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user