Skip to content
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

Read_string blocking #21

Open
TheBlindM opened this issue Mar 10, 2024 · 1 comment
Open

Read_string blocking #21

TheBlindM opened this issue Mar 10, 2024 · 1 comment

Comments

@TheBlindM
Copy link

TheBlindM commented Mar 10, 2024

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant