-
-
Notifications
You must be signed in to change notification settings - Fork 200
feat: offline caching (inproc & breakpad) #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Before "revert separate caching folder implementation" #1461
Cast cache_max_age to time_t to avoid implicit signedness conversion between uint64_t and time_t. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add explicit static_cast<time_t>() for cache_max_age to fix -Wsign-conversion warning on Windows with clang-cl. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
For consistency with time-related operations throughout the codebase. This adds a time.h dependency to the public header, but it's a lightweight standard C header available since C89. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move size accumulation into else branch so age-pruned files don't count toward size limit. Remove the size subtraction on prune which caused bin-packing behavior (keeping older smaller files while removing newer larger ones). Add test for size-based pruning order. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Check CreateFileW return value before calling SetFileTime/CloseHandle - Change TEST_CHECK to TEST_ASSERT since mtime setup is a precondition Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cache_dir is NULL when cache_keep is false, and sentry__path_free handles NULL safely. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Crashpad's AgePruneCondition and DatabaseSizePruneCondition only accept days and KB respectively, causing precision loss for sub-day ages and sub-KB sizes. Replace them with MaxAgePruneCondition (seconds) and MaxSizePruneCondition (bytes) that handle zero as "no limit" internally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Re-order cache_max_items before max_size/max_age for visibility as the most relevant default limit. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…disabled When cache_keep is false, the crashpad database should be pruned with the original upstream defaults (2 days, 8 MB) rather than the cache_max options which default to 0 (disabled). This preserves the existing pruning behavior for users who have not opted into offline caching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| data->db->CleanDatabase(60 * 60 * 24 * 2); | ||
| // large. When offline caching is enabled, the cache_max_* options are | ||
| // used instead. | ||
| time_t max_age = 2 * 24 * 60 * 60; // 2 days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extracting these constants somewhere would make sense (instead of keeping them as crashpad-only defaults in a function)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just some legacy defaults that were used by the crashpad backend before offline caching was introduced. These defaults are specific to the crashpad backend and are not used anywhere else. The idea is to retain full backwards compatibility by using the old legacy defaults unless the user opts in for offline caching. I updated the comments - I hope it's clear now :)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Avoid short-circuit evaluation skipping stateful conditions by combining MaxItemsPruneCondition, MaxSizePruneCondition, and MaxAgePruneCondition into a single CachePruneCondition that evaluates all checks unconditionally. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Hey @JoshuaMoelans, we decided to merge these two Don't hesitate to drop comments when you're back, and I'll follow up if there's anything. |
Summary
Adds offline caching support for the
inprocandbreakpadbackends, allowing envelopes to be persisted locally for debugging and offline scenarios. When enabled, envelopes are retained in acache/subdirectory within the database path, regardless of whether the send succeeds or fails.On startup, the cache is pruned based on the configured limits (max items, age, size), removing entries from oldest to newest until constraints are satisfied. The pruning algorithm is based on Crashpad's
prune_crash_reports.cc.API
New options:
sentry_options_set_cache_keep(opts, int enabled)- Enables/disables offline cachingsentry_options_set_cache_max_items(opts, size_t items)- Maximum number of cache entries (default: 30)sentry_options_set_cache_max_size(opts, size_t bytes)- Maximum cache directory size (no default max size)sentry_options_set_cache_max_age(opts, time_t seconds)- Maximum age for cache entries (no default max age)Usage
Comparison
cache_keep(default: off)cache_max_items(30)maxCacheItems(30)maxCacheItems(30)cache_max_size(0)cache_max_age(0)Limitations
Related
Test Plan
test_cache.c)test_integration_cache.py)Co-authored-by: @JoshuaMoelans
Closes: #1461