diff --git a/CHANGELOG.md b/CHANGELOG.md index 366aab86..c6324e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Added +- Rule GCI604 defining a threshold for a max-timeout for retryable methods ## [Unreleased] ### Added diff --git a/src/main/rules/GCI604/GCI604.json b/src/main/rules/GCI604/GCI604.json new file mode 100644 index 00000000..26b82024 --- /dev/null +++ b/src/main/rules/GCI604/GCI604.json @@ -0,0 +1,17 @@ +{ + "title": "limit retry", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant/Issue", + "constantCost": "5min" + }, + "tags": [ + "sobriety", + "environment", + "creedengo", + "spring-boot", + "eco-design" + ], + "defaultSeverity": "Major" +} diff --git a/src/main/rules/GCI604/java/GCI604.asciidoc b/src/main/rules/GCI604/java/GCI604.asciidoc new file mode 100644 index 00000000..c6731fb0 --- /dev/null +++ b/src/main/rules/GCI604/java/GCI604.asciidoc @@ -0,0 +1,31 @@ +Spring Retry: Inconsistent configuration += Inconsistent Spring Retry Configuration + +An inconsistent configuration of Spring Retry can lead to blocking threads and increased energy usage. + +With Spring Retry, you can mark operations as retryable using `@Retryable`. However, misconfiguration (e.g., too many retries or long backoff periods) can block threads unnecessarily — consuming CPU cycles and energy. + +This rule applies to usages of `@Retryable` only. +A threshold `max.timeout` defines the maximum acceptable blocking time (in milliseconds). + +`max.timeout=50000` + +== Noncompliant Code Example + +[source,java] +---- +@Retryable(maxAttempts = 4, backoff = @Backoff(delay = 10, multiplier = 100)) +void retryService(String sql); +---- + +In this example, retry delays compound to a total retry time of over 10,000,000 ms (10,000 seconds), which exceeds the `max.timeout` threshold. + +== Compliant Solution + +[source,java] +---- +@Retryable(maxAttempts = 5, backoff = @Backoff(delay = 10)) +void retryService(String sql); +---- + +This configuration limits the total blocking time to 50 ms (5 attempts × 10 ms), keeping energy usage efficient and thread usage minimal.