diff --git a/providers/providers.go b/providers/providers.go index 2d7f25b024..63f493bafd 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -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 diff --git a/providers/providers_test.go b/providers/providers_test.go index 947d5160b7..4651ac0228 100644 --- a/providers/providers_test.go +++ b/providers/providers_test.go @@ -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" ) @@ -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) +}