Skip to content

Commit a264f66

Browse files
jpnurmiclaude
andcommitted
fix(retry): prevent startup poll from re-processing same-session envelopes
The startup poll used `ts >= startup_time` to skip envelopes written after startup. With second-precision timestamps, this also skipped cross-session envelopes written in the same second as a fast restart. Reset `startup_time` in `sentry__retry_enqueue` so the startup poll falls through to the backoff path for same-session envelopes. The bgworker processes the send task (immediate) before the startup poll (delayed), so by the time the poll fires, `startup_time` is already 0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 60f836c commit a264f66

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/sentry_retry.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ sentry__retry_send(sentry_retry_t *retry, uint64_t before,
193193

194194
size_t total = 0;
195195
size_t eligible = 0;
196-
uint64_t now = before ? 0 : (uint64_t)time(NULL);
196+
uint64_t now = before > 0 ? 0 : (uint64_t)time(NULL);
197197

198198
const sentry_path_t *p;
199199
while ((p = sentry__pathiter_next(piter)) != NULL) {
@@ -204,7 +204,7 @@ sentry__retry_send(sentry_retry_t *retry, uint64_t before,
204204
if (!sentry__retry_parse_filename(fname, &ts, &count, &uuid)) {
205205
continue;
206206
}
207-
if (before && ts >= before) {
207+
if (before > 0 && ts >= before) {
208208
continue;
209209
}
210210
total++;
@@ -279,6 +279,8 @@ void
279279
sentry__retry_enqueue(sentry_retry_t *retry, const sentry_envelope_t *envelope)
280280
{
281281
sentry__retry_write_envelope(retry, envelope);
282+
// prevent the startup poll from re-processing this session's envelope
283+
retry->startup_time = 0;
282284
sentry__bgworker_submit_delayed(
283285
retry->bgworker, retry_poll_task, NULL, retry, SENTRY_RETRY_INTERVAL);
284286
}

tests/unit/test_retry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int
5050
count_eligible_files(const sentry_path_t *dir, uint64_t before)
5151
{
5252
int eligible = 0;
53-
uint64_t now = before ? 0 : (uint64_t)time(NULL);
53+
uint64_t now = before > 0 ? 0 : (uint64_t)time(NULL);
5454
sentry_pathiter_t *iter = sentry__path_iter_directory(dir);
5555
const sentry_path_t *file;
5656
while (iter && (file = sentry__pathiter_next(iter)) != NULL) {
@@ -61,7 +61,7 @@ count_eligible_files(const sentry_path_t *dir, uint64_t before)
6161
if (!sentry__retry_parse_filename(name, &ts, &count, &uuid)) {
6262
continue;
6363
}
64-
if (before && ts >= before) {
64+
if (before > 0 && ts >= before) {
6565
continue;
6666
}
6767
if (!before && (now - ts) < sentry__retry_backoff(count)) {

0 commit comments

Comments
 (0)