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

client: Fix error handling in push mode copy (from Incus) #14076

Merged
merged 1 commit into from
Sep 10, 2024
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
36 changes: 32 additions & 4 deletions client/lxd_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,
target.Certificate = info.Certificate
sourceReq.Target = &target

return r.tryMigrateInstance(source, instance.Name, sourceReq, info.Addresses)
return r.tryMigrateInstance(source, instance.Name, sourceReq, info.Addresses, op)
}

// Get source server connection information
Expand Down Expand Up @@ -1114,7 +1114,7 @@ func (r *ProtocolLXD) RenameInstance(name string, instance api.InstancePost) (Op

// tryMigrateInstance attempts to migrate a specific instance from a source server to one of the target URLs.
// The function runs the migration operation asynchronously and returns a RemoteOperation to track the progress and handle any errors.
func (r *ProtocolLXD) tryMigrateInstance(source InstanceServer, name string, req api.InstancePost, urls []string) (RemoteOperation, error) {
func (r *ProtocolLXD) tryMigrateInstance(source InstanceServer, name string, req api.InstancePost, urls []string, op Operation) (RemoteOperation, error) {
if len(urls) == 0 {
return nil, fmt.Errorf("The target server isn't listening on the network")
}
Expand All @@ -1126,6 +1126,9 @@ func (r *ProtocolLXD) tryMigrateInstance(source InstanceServer, name string, req
operation := req.Target.Operation

// Forward targetOp to remote op
chConnect := make(chan error, 1)
chWait := make(chan error, 1)

go func() {
success := false
var errors []remoteOperationResult
Expand Down Expand Up @@ -1159,10 +1162,35 @@ func (r *ProtocolLXD) tryMigrateInstance(source InstanceServer, name string, req
break
}

if !success {
rop.err = remoteOperationError("Failed instance migration", errors)
if success {
chConnect <- nil
close(chConnect)
} else {
chConnect <- remoteOperationError("Failed instance migration", errors)
close(chConnect)

if op != nil {
_ = op.Cancel()
}
}
}()

if op != nil {
go func() {
chWait <- op.Wait()
close(chWait)
}()
}

go func() {
var err error

select {
case err = <-chConnect:
case err = <-chWait:
}

rop.err = err
close(rop.chDone)
}()

Expand Down
Loading