Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/main/rules/GCI604/GCI604.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"title": "limit retry",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the title to something more explicit

"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant/Issue",
"constantCost": "5min"
},
"tags": [
"sobriety",
"environment",
"creedengo",
"spring-boot",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not only for spring-boot but also for "spring"

"eco-design"
],
"defaultSeverity": "Major"
}
31 changes: 31 additions & 0 deletions src/main/rules/GCI604/java/GCI604.asciidoc
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add some references like :

if we respect our process for a new rule ... we have to give evidence to prove that its a good idea like :


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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the good value for max timeout ? maybe also describe de "maxDelay" parameter


== 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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe give some other compliant examples with acceptable "multiplier" or the "maxDelay" given to limit the maximum timeout
because we can have a relevant use case that the multiplier is relevant (for example, call an external URL to limit de spend of too much call tokens) ... but I agree, we have to control it not to consume a lot of resources.

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.