Skip to content

Commit 37004bf

Browse files
jpnurmiclaude
andcommitted
fix(database): remove orphan pass to fix race with transport thread
The orphan pass in sentry__cleanup_cache deleted attachment dirs without a matching .envelope file. This raced with the transport background thread: process_old_runs submits envelopes to the transport and deletes the .run files, but the transport hasn't yet written the retry .envelope to cache when the orphan pass runs, causing it to delete the attachment dir before the TUS upload can use it. All cleanup paths are already covered without the orphan pass: the first pass deletes attachment dirs alongside pruned envelopes, handle_result cleans up on retry discard, process_old_runs handles materialization failure, and sentry__db_remove_large_attachment handles TUS success. Also restores the cache_keep/http_retry gate on sentry__cleanup_cache since without the orphan pass there's no reason to run it otherwise. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c379816 commit 37004bf

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

src/sentry_core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ sentry_init(sentry_options_t *options)
290290
backend->prune_database_func(backend);
291291
}
292292

293-
sentry__cleanup_cache(options);
293+
if (options->cache_keep || options->http_retry) {
294+
sentry__cleanup_cache(options);
295+
}
294296

295297
if (options->auto_session_tracking) {
296298
sentry_start_session();

src/sentry_database.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -715,38 +715,6 @@ sentry__cleanup_cache(const sentry_options_t *options)
715715

716716
sentry_free(entries);
717717

718-
// Second pass: remove orphaned attachment directories
719-
// (dirs without a matching .envelope, e.g. envelope deleted by
720-
// materialization failure or TUS disabled)
721-
iter = sentry__path_iter_directory(cache_dir);
722-
while (iter && (entry = sentry__pathiter_next(iter)) != NULL) {
723-
if (!sentry__path_is_dir(entry)) {
724-
continue;
725-
}
726-
const char *dirname = sentry__path_filename(entry);
727-
if (!dirname || strlen(dirname) != 36) {
728-
continue;
729-
}
730-
bool has_envelope = false;
731-
sentry_pathiter_t *fiter = sentry__path_iter_directory(cache_dir);
732-
const sentry_path_t *f;
733-
while (fiter && (f = sentry__pathiter_next(fiter)) != NULL) {
734-
if (sentry__path_is_dir(f)) {
735-
continue;
736-
}
737-
const char *fname = sentry__path_filename(f);
738-
if (fname && strstr(fname, dirname)) {
739-
has_envelope = true;
740-
break;
741-
}
742-
}
743-
sentry__pathiter_free(fiter);
744-
if (!has_envelope) {
745-
sentry__path_remove_all(entry);
746-
}
747-
}
748-
sentry__pathiter_free(iter);
749-
750718
sentry__path_free(cache_dir);
751719
}
752720

0 commit comments

Comments
 (0)