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

Avoid task cancellation on service init failure #3707

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use ddm_admin_client::{Client as DdmAdminClient, DdmError};
use dpd_client::{types as DpdTypes, Client as DpdClient, Error as DpdError};
use dropshot::HandlerTaskMode;
use flate2::bufread::GzDecoder;
use futures::stream::{self, StreamExt, TryStreamExt};
use futures::stream::{self, StreamExt};
use illumos_utils::addrobj::AddrObject;
use illumos_utils::addrobj::IPV6_LINK_LOCAL_NAME;
use illumos_utils::dladm::{Dladm, Etherstub, EtherstubVnic, PhysicalLink};
Expand Down Expand Up @@ -1919,30 +1919,49 @@ impl ServiceManager {
{
return Err(Error::BadServiceRequest {
service: name,
message: "Should initialize zone twice".to_string(),
message: "Should not initialize zone twice".to_string(),
});
}

// We initialize all the zones we can, but only return the first error.
let local_existing_zones = Arc::new(Mutex::new(existing_zones));
let first_err = Arc::new(Mutex::new(None));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but as written shouldn't this be last_err?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #3709 , pulled it out to not block the build for folks MUPdating

stream::iter(requests)
.map(Ok::<_, Error>)
.try_for_each_concurrent(None, |request| {
// WARNING: Do not use "try_for_each_concurrent" here -- if you do,
// it's possible that the future will cancel other ongoing requests
// to "initialize_zone".
.for_each_concurrent(None, |request| {
let local_existing_zones = local_existing_zones.clone();
let first_err = first_err.clone();
async move {
// TODO-correctness: It seems like we should continue with the other
// zones, rather than bail out of this method entirely.
let running_zone = self
match self
.initialize_zone(
request,
// filesystems=
&[],
)
.await?;
local_existing_zones.lock().await.push(running_zone);
Ok(())
.await
{
Ok(running_zone) => {
local_existing_zones
.lock()
.await
.push(running_zone);
}
Err(err) => {
*first_err.lock().await = Some(err);
}
}
}
})
.await?;
.await;

if let Some(err) = Arc::into_inner(first_err)
.expect("Should have last reference")
.into_inner()
{
return Err(err);
}

Ok(())
}
Expand Down