Skip to content

Commit 06b8ef4

Browse files
jpnurmiclaude
andcommitted
fix(retry): prevent retry flush from consuming shutdown timeout
Drop the delayed retry_poll_task before bgworker_flush to prevent it from delaying the flush_task by min(retry_interval, timeout). Subtract elapsed flush time from the shutdown timeout so the total is bounded. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c06a02f commit 06b8ef4

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/sentry_retry.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,22 @@ retry_flush_task(void *_retry, void *_state)
314314
}
315315
}
316316

317+
static bool
318+
drop_task_cb(void *_data, void *_ctx)
319+
{
320+
(void)_data;
321+
(void)_ctx;
322+
return true;
323+
}
324+
317325
void
318326
sentry__retry_flush(sentry_retry_t *retry, uint64_t timeout)
319327
{
320328
if (retry) {
329+
// drop the delayed poll that would stall bgworker_flush
330+
sentry__bgworker_foreach_matching(
331+
retry->bgworker, retry_poll_task, drop_task_cb, NULL);
332+
sentry__atomic_store(&retry->scheduled, 0);
321333
sentry__bgworker_submit(retry->bgworker, retry_flush_task, NULL, retry);
322334
sentry__bgworker_flush(retry->bgworker, timeout);
323335
}

src/transports/sentry_http_transport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ http_transport_shutdown(uint64_t timeout, void *transport_state)
305305
sentry_bgworker_t *bgworker = transport_state;
306306
http_transport_state_t *state = sentry__bgworker_get_state(bgworker);
307307

308-
// flush drains in-flight retries; shutdown is near-instant afterward
308+
uint64_t started = sentry__monotonic_time();
309309
sentry__retry_flush(state->retry, timeout);
310+
uint64_t elapsed = sentry__monotonic_time() - started;
311+
uint64_t remaining = elapsed < timeout ? timeout - elapsed : 0;
310312

311-
int rv = sentry__bgworker_shutdown(bgworker, timeout);
313+
int rv = sentry__bgworker_shutdown(bgworker, remaining);
312314
if (rv != 0) {
313315
sentry__retry_dump_queue(state->retry, http_send_task);
314316
if (state->shutdown_client) {

0 commit comments

Comments
 (0)