AspectUnk / russh-sftp

SFTP subsystem supported server and client for Russh
Apache License 2.0
56 stars 18 forks source link

Read_string blocking #21

Open TheBlindM opened 5 months ago

TheBlindM commented 5 months ago

When I use read_string on a server with high latency, it works fine for the first time, but it keeps blocking here on the second call. For servers with low latency, read_string remains normal

async fn save_brief_resource_info(&self) -> Result<()> {
         let home_dir = AsyncSshUtil::get_home_dir(&self.session).await?;
        info!("save_brief_resource_info read_string start");
        let sftp = self.sftp.lock().await;
        info!("save_brief_resource_info read_string start2");
        let mut remote_file = &mut sftp.open(format!("{}/.tshell/output.stats", home_dir).as_str()).await?;
        info!("save_brief_resource_info read_string start3");
        let mut script_yaml = String::new();
        remote_file.rewind().await.unwrap();
        remote_file.read_to_string(&mut script_yaml).await?;
        remote_file.rewind().await.unwrap();
        remote_file.shutdown().await.unwrap();
        info!("save_brief_resource_info read_string start4");
        info!("save_brief_resource_info read_string end");
        let system_info: SystemInfo = serde_json::from_str(script_yaml.as_str())?;

        if !MAP.contains_key(&self.channel_id) {
            MAP.insert(self.channel_id.clone(), LinkedList::new());
        }

        let mut cache = MAP.get_mut(&self.channel_id)?;

        if cache.len() == 60 {
            cache.pop_front();
        }
        cache.push_back(system_info);
        Ok(())
    }

image

TheBlindM commented 5 months ago

Maybe it's caused by tokio,It is normal for me to execute multiple times under a small demo project