Skip to content

Commit 9b1c1be

Browse files
jpnurmiclaude
andcommitted
fix(database): run cache cleanup unconditionally, remove orphan dirs immediately
sentry__cleanup_cache must run regardless of cache_keep/http_retry since large attachment dirs now live in the cache directory and need cleanup even when caching is disabled. Orphaned attachment dirs (no matching .envelope) are unconditionally useless — remove them immediately instead of age-gating. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fbf446d commit 9b1c1be

2 files changed

Lines changed: 25 additions & 33 deletions

File tree

src/sentry_core.c

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

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

297295
if (options->auto_session_tracking) {
298296
sentry_start_session();

src/sentry_database.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -709,43 +709,37 @@ sentry__cleanup_cache(const sentry_options_t *options)
709709

710710
sentry_free(entries);
711711

712-
// Second pass: age-prune orphaned attachment directories
712+
// Second pass: remove orphaned attachment directories
713713
// (dirs without a matching .envelope, e.g. envelope deleted by
714714
// materialization failure or TUS disabled)
715-
if (options->cache_max_age > 0) {
716-
iter = sentry__path_iter_directory(cache_dir);
717-
while (iter && (entry = sentry__pathiter_next(iter)) != NULL) {
718-
if (!sentry__path_is_dir(entry)) {
719-
continue;
720-
}
721-
const char *dirname = sentry__path_filename(entry);
722-
if (!dirname || strlen(dirname) != 36) {
723-
continue;
724-
}
725-
time_t dir_mtime = sentry__path_get_mtime(entry);
726-
if (dir_mtime >= oldest_allowed) {
715+
iter = sentry__path_iter_directory(cache_dir);
716+
while (iter && (entry = sentry__pathiter_next(iter)) != NULL) {
717+
if (!sentry__path_is_dir(entry)) {
718+
continue;
719+
}
720+
const char *dirname = sentry__path_filename(entry);
721+
if (!dirname || strlen(dirname) != 36) {
722+
continue;
723+
}
724+
bool has_envelope = false;
725+
sentry_pathiter_t *fiter = sentry__path_iter_directory(cache_dir);
726+
const sentry_path_t *f;
727+
while (fiter && (f = sentry__pathiter_next(fiter)) != NULL) {
728+
if (sentry__path_is_dir(f)) {
727729
continue;
728730
}
729-
bool has_envelope = false;
730-
sentry_pathiter_t *fiter = sentry__path_iter_directory(cache_dir);
731-
const sentry_path_t *f;
732-
while (fiter && (f = sentry__pathiter_next(fiter)) != NULL) {
733-
if (sentry__path_is_dir(f)) {
734-
continue;
735-
}
736-
const char *fname = sentry__path_filename(f);
737-
if (fname && strstr(fname, dirname)) {
738-
has_envelope = true;
739-
break;
740-
}
741-
}
742-
sentry__pathiter_free(fiter);
743-
if (!has_envelope) {
744-
sentry__path_remove_all(entry);
731+
const char *fname = sentry__path_filename(f);
732+
if (fname && strstr(fname, dirname)) {
733+
has_envelope = true;
734+
break;
745735
}
746736
}
747-
sentry__pathiter_free(iter);
737+
sentry__pathiter_free(fiter);
738+
if (!has_envelope) {
739+
sentry__path_remove_all(entry);
740+
}
748741
}
742+
sentry__pathiter_free(iter);
749743

750744
sentry__path_free(cache_dir);
751745
}

0 commit comments

Comments
 (0)