Skip to content

Commit

Permalink
🐛 fix panic in osRetry logic (#3175)
Browse files Browse the repository at this point in the history
* fix panic in osRetry logic

Signed-off-by: Ivan Milchev <[email protected]>

* add test

Signed-off-by: Ivan Milchev <[email protected]>

---------

Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Feb 1, 2024
1 parent f8712b2 commit 74ea320
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func osRetry(f func() error, maxRetry int) error {
return nil
}

if errors.As(err, syscall.EBUSY) || errors.As(err, syscall.EAGAIN) {
if errno, ok := err.(syscall.Errno); ok && errno.Temporary() {
time.Sleep(osRetryDuration)
} else {
return err
Expand Down
12 changes: 12 additions & 0 deletions providers/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package providers

import (
"syscall"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
)
Expand Down Expand Up @@ -57,3 +59,13 @@ func TestProviderShutdown(t *testing.T) {
require.NoError(t, err)
require.True(t, s.isCloseOrShutdown())
}

func TestOsRetry_RetryableError(t *testing.T) {
funcCounter := 0
testFunc := func() error {
funcCounter++
return syscall.EAGAIN
}
assert.NoError(t, osRetry(testFunc, 2))
assert.Equal(t, 2, funcCounter)
}

0 comments on commit 74ea320

Please sign in to comment.