|
| 1 | +package transitioner |
| 2 | + |
| 3 | +import ( |
| 4 | + "net" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/aws/aws-sdk-go/aws/awserr" |
| 8 | +) |
| 9 | + |
| 10 | +// isRetryableError determines if an error should trigger a requeue instead of moving to Healing phase |
| 11 | +// Retryable errors typically include network timeouts and transient AWS service errors |
| 12 | +func isRetryableError(err error) bool { |
| 13 | + if err == nil { |
| 14 | + return false |
| 15 | + } |
| 16 | + |
| 17 | + // Check for network errors (timeouts, connection refused, etc.) |
| 18 | + if netErr, ok := err.(net.Error); ok { |
| 19 | + if netErr.Timeout() { |
| 20 | + return true |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // Check error string for common network patterns |
| 25 | + errStr := err.Error() |
| 26 | + networkPatterns := []string{ |
| 27 | + "i/o timeout", |
| 28 | + "dial tcp", |
| 29 | + "connection reset", |
| 30 | + "connection refused", |
| 31 | + "connection timeout", |
| 32 | + "TLS handshake timeout", |
| 33 | + "broken pipe", |
| 34 | + "unexpected EOF", |
| 35 | + } |
| 36 | + |
| 37 | + for _, pattern := range networkPatterns { |
| 38 | + if strings.Contains(errStr, pattern) { |
| 39 | + return true |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // Check for AWS SDK transient errors |
| 44 | + if awsErr, ok := err.(awserr.Error); ok { |
| 45 | + code := awsErr.Code() |
| 46 | + // Common transient AWS error codes |
| 47 | + transientCodes := map[string]bool{ |
| 48 | + "Throttling": true, |
| 49 | + "ThrottlingException": true, |
| 50 | + "TooManyRequestsException": true, |
| 51 | + "RequestLimitExceeded": true, |
| 52 | + "SlowDown": true, |
| 53 | + "ServiceUnavailable": true, |
| 54 | + "ServiceUnavailableException": true, |
| 55 | + "InternalFailure": true, |
| 56 | + "InternalError": true, |
| 57 | + "InternalServerError": true, |
| 58 | + "RequestTimeout": true, |
| 59 | + "RequestTimedOut": true, |
| 60 | + } |
| 61 | + |
| 62 | + if transientCodes[code] { |
| 63 | + return true |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return false |
| 68 | +} |
0 commit comments