dockworker icon indicating copy to clipboard operation
dockworker copied to clipboard

Fixed Send + Sync issue with the list_containers function when called by tokio::task::spawn

Open DrWalrus1 opened this issue 1 year ago • 1 comments

fixes #159

The example change probably won't need to get merged in. Just wanted to show some context that caused compilation failures in some contexts

DrWalrus1 avatar Jun 11 '24 11:06 DrWalrus1

@DrWalrus1 I have confirmed the issue reproduction, but I have a few questions. First, it seems that there are multiple places in the code that have a similar issue aside from list_containers. For instance, is there no problem with stop_container ? Also, instead of encapsulating the entire creation of the URL parameters in a closure, wouldn’t it be possible to resolve the issue by handling it as shown below?

let param = {
    let mut param = url::form_urlencoded::Serializer::new(String::new());
    param.append_pair("all", &(all.unwrap_or(false) as u64).to_string());
    if let Some(limit) = limit {
        param.append_pair("limit", &limit.to_string());
    }
    param.append_pair("size", &(size.unwrap_or(false) as u64).to_string());
    param.append_pair("filters", &serde_json::to_string(&filters).unwrap());
    param.finish()
};
debug!("filter: {}", serde_json::to_string(&filters).unwrap());
let res = self
    .http_client()
    .get(self.headers(), &format!("/containers/json?{}", param))
    .await?;
api_result(res).map_err(Into::into)

eldesh avatar Oct 07 '24 05:10 eldesh

Notes taken aboard. I've expanded the fixes as you advised

DrWalrus1 avatar Oct 07 '24 10:10 DrWalrus1

Look good thank you 👍

eldesh avatar Oct 10 '24 09:10 eldesh