Skip to content

Commit 3936df2

Browse files
[exporter/elasticsearch] Fix retry backoff overflow handling edge case (open-telemetry#46178)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Guard exponential retry backoff against duration overflow so delay growth remains bounded and correctly caps at max_interval while preserving jitter. Co-authored-by: Cursor <cursoragent@cursor.com> <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent efbd9c6 commit 3936df2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
change_type: bug_fix
2+
component: exporter/elasticsearch
3+
note: Fix retry exponential backoff overflow handling edge case
4+
issues: [46178]
5+
subtext: |
6+
The retry delay growth now guards against duration overflow while preserving
7+
exponential backoff with jitter, so retries cap correctly at the configured
8+
max interval even for large attempt counts.
9+
change_logs: [user]

exporter/elasticsearchexporter/esclient.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,17 @@ func addrsToURLs(addrs []string) ([]*url.URL, error) {
260260
return urls, nil
261261
}
262262

263+
// createElasticsearchBackoffFunc creates an exponential backoff with equal jitter.
263264
func createElasticsearchBackoffFunc(config *RetrySettings) func(int) time.Duration {
264265
if !config.Enabled {
265266
return nil
266267
}
267268

268269
return func(attempts int) time.Duration {
269-
next := min(config.MaxInterval, config.InitialInterval*(1<<(attempts-1)))
270+
next := config.InitialInterval << (attempts - 1) // config.InitialInterval * 2 ^ (attempts - 1)
271+
if next <= 0 || next > config.MaxInterval { // guard against overflow
272+
next = config.MaxInterval
273+
}
270274
nextWithJitter := next/2 + time.Duration(rand.Float64()*float64(next/2))
271275
return nextWithJitter
272276
}

0 commit comments

Comments
 (0)