Skip to content

Commit

Permalink
fix: scope of err variable while migrating volume
Browse files Browse the repository at this point in the history
Fix the scope of the err variable while migrating a volume.

The root of this problem is that in case a migration revert is
attempted, `err` is re-defined in a defer'ed anonymous function. This
shadows the definition of the variable `err` in the outer scope, which
causes the original error during the migration to be lost.
The simple fix is to define a different error and wrap the original
error with a message containing the new error. This avoids redefining
`err`, making it available with its original value in the defer'ed
function.

Signed-off-by: Moritz Röhrich <moritz.rohrich@suse.com>
  • Loading branch information
m-ildefons authored and David Ko committed Dec 8, 2023
1 parent dccf8de commit 268b1d6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3824,18 +3824,18 @@ func (c *VolumeController) processMigration(v *longhorn.Volume, es map[string]*l

log.Warnf("The migration engine or all migration replicas crashed, will clean them up now")

currentEngine, err := c.getCurrentEngineAndCleanupOthers(v, es)
if err != nil {
err = errors.Wrap(err, "failed to get the current engine and clean up others during the migration revert")
currentEngine, err2 := c.getCurrentEngineAndCleanupOthers(v, es)
if err2 != nil {
err = errors.Wrapf(err, "failed to get the current engine and clean up others during the migration revert: %v", err2)
return
}

for _, r := range rs {
if r.Spec.EngineName == currentEngine.Name {
continue
}
if err := c.deleteReplica(r, rs); err != nil {
err = errors.Wrapf(err, "failed to delete the migration replica %v during the migration revert", r.Name)
if err2 := c.deleteReplica(r, rs); err2 != nil {
err = errors.Wrapf(err, "failed to delete the migration replica %v during the migration revert: %v", r.Name, err2)
return
}
}
Expand Down

0 comments on commit 268b1d6

Please sign in to comment.