Skip to content

Commit 180fe75

Browse files
marcboquetsl0thentr0py
authored andcommitted
fix(sidekiq): Report error when retry limit is below attempt_threshold
When a job's `retry` option is lower than its `attempt_threshold` (e.g. `retry: 1` with `attempt_threshold: 3`), the error handler skipped every attempt and the job was silently dropped — it died before ever reaching the threshold. Cap the threshold at the job's final attempt so these jobs still report before entering the dead set. Jobs whose retry count meets or exceeds the threshold behave exactly as before.
1 parent e747740 commit 180fe75

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
### Bug Fixes 🐛
4+
5+
- (sidekiq) Report final attempt when retry limit is below `attempt_threshold` by @marcboquet in [#XXXX](https://github.com/getsentry/sentry-ruby/pull/XXXX)
6+
17
## 6.5.0
28

39
### New Features ✨

sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ def call(ex, context, sidekiq_config = nil)
4343
# attempt 2 - this is your first retry so retry_count is 0
4444
# attempt 3 - you have retried once, retry_count is 1
4545
attempt = retry_count.nil? ? 1 : retry_count.to_i + 2
46+
# Cap at the final attempt so jobs with fewer retries than the threshold still report.
47+
effective_threshold = [attempt_threshold, retry_limit(context, sidekiq_config) + 1].min
4648

47-
return if attempt < attempt_threshold
49+
return if attempt < effective_threshold
4850
end
4951

5052
Sentry::Sidekiq.capture_exception(

sentry-sidekiq/spec/sentry/sidekiq_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ def retry_last_failed_job
141141
retry_last_failed_job
142142
expect(transport.events.count).to eq(0)
143143
end
144+
145+
it "reports on the final attempt when retry limit is below the threshold" do
146+
worker = Class.new(SadWorker)
147+
worker.sidekiq_options attempt_threshold: 3, retry: 1
148+
149+
execute_worker(processor, worker)
150+
expect(transport.events.count).to eq(0)
151+
152+
retry_last_failed_job
153+
expect(transport.events.count).to eq(1)
154+
end
144155
end
145156

146157
context "with config.report_only_dead_jobs = true" do

0 commit comments

Comments
 (0)