Skip to content

Commit

Permalink
Fix retry logic within devmapper device deactivation
Browse files Browse the repository at this point in the history
Signed-off-by: Swagat Bora <sbora@amazon.com>
(cherry picked from commit 6ae3e5d)

Signed-off-by: Swagat Bora <sbora@amazon.com>
  • Loading branch information
swagatbora90 committed Feb 10, 2023
1 parent c553746 commit d528415
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions snapshots/devmapper/pool_device.go
Expand Up @@ -89,6 +89,15 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
return poolDevice, nil
}

func skipRetry(err error) bool {
if err == nil {
return true // skip retry if no error
} else if !errors.Is(err, unix.EBUSY) {
return true // skip retry if error is not due to device or resource busy
}
return false
}

func retry(ctx context.Context, f func() error) error {
var (
maxRetries = 100
Expand All @@ -98,9 +107,8 @@ func retry(ctx context.Context, f func() error) error {

for attempt := 1; attempt <= maxRetries; attempt++ {
retryErr = f()
if retryErr == nil {
return nil
} else if retryErr != unix.EBUSY {

if skipRetry(retryErr) {
return retryErr
}

Expand Down

0 comments on commit d528415

Please sign in to comment.