You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VPC and VPC Subnet deletion needs to check for network interfaces #738
Currently, we delete VPCs and VPC Subnets (and maybe other container-like resources) without checking for anything still being inside them. We should perform that check, using the omicron_nexus::db::update_and_check tooling to verify there are no non-soft-deleted VPC Subnets when we delete a VPC, or Network Interfaces when we delete a VPC Subnet.
I ran into this again while working on a PR to solve #1134. In Nexus::instance_create_network_interface, we first lookup the VPC and VPC Subnet before adding a new interface for an instance. I've updated the internals of the query to check that the instance exists and is stopped without a window for a TOCTOU, but this isn't sufficient. The VPC and VPC Subnet both could be removed after they're fetched, but before we insert the interface for the instance.
The solution is really to add additional parent-child relationships, via the DatastoreCollection trait. The VPC already has VpcRouters as children, but also needs the VpcSubnet. The VpcSubnet meanwhile needs the NetworkInterface as its own children. This addresses the other side of this issue: concurrently inserting a child while the parent is being deleted.
The deletion side is still racy. But rather than using update_and_check, as I suggested in the original issue description, we can instead follow the patttern used when deleting other resources:
Fetch the parent collection, most notably its rcgen
Fetch any children, and fail the request if we find one
Delete the parent, conditional on that rcgen not having changed. If we update zero rows, it's assumed to have changed and we fail the request.
One complication here is that when deleting an interface, we need to fetch its parent, VpcSubnet, so that we can make deletion conditional on its rcgen being the same. We don't currently do that, so we've got another trip to the DB. Not the end of the world, but we may want to revisit the question of whether network interfaces are children of the VPC Subnet or the Instance. Neither is exactly right, since they're an association between the two.
Activity
bnaecker commentedon Jun 16, 2022
I ran into this again while working on a PR to solve #1134. In
Nexus::instance_create_network_interface, we first lookup the VPC and VPC Subnet before adding a new interface for an instance. I've updated the internals of the query to check that the instance exists and is stopped without a window for a TOCTOU, but this isn't sufficient. The VPC and VPC Subnet both could be removed after they're fetched, but before we insert the interface for the instance.The solution is really to add additional parent-child relationships, via the
DatastoreCollectiontrait. The VPC already hasVpcRouters as children, but also needs theVpcSubnet. TheVpcSubnetmeanwhile needs theNetworkInterfaceas its own children. This addresses the other side of this issue: concurrently inserting a child while the parent is being deleted.The deletion side is still racy. But rather than using
update_and_check, as I suggested in the original issue description, we can instead follow the patttern used when deleting other resources:rcgenrcgennot having changed. If we update zero rows, it's assumed to have changed and we fail the request.bnaecker commentedon Jun 16, 2022
One complication here is that when deleting an interface, we need to fetch its parent,
VpcSubnet, so that we can make deletion conditional on itsrcgenbeing the same. We don't currently do that, so we've got another trip to the DB. Not the end of the world, but we may want to revisit the question of whether network interfaces are children of the VPC Subnet or the Instance. Neither is exactly right, since they're an association between the two.bnaecker commentedon Jul 26, 2022
Closed by #1483