ref(core): Measure the hostname cache TTL on a monotonic ticker (JAVA-579) - #6100
Draft
runningcode wants to merge 2 commits into
Draft
ref(core): Measure the hostname cache TTL on a monotonic ticker (JAVA-579)#6100runningcode wants to merge 2 commits into
runningcode wants to merge 2 commits into
Conversation
…-579) HostnameCache stored an absolute expiry built from currentTimeMillis and compared it against a fresh reading, so a device time change resized the 5h TTL: a backward step extended it by the size of the step, a forward step expired the cache early. It now holds a Deadline on a MonotonicTicker. The field also no longer starts at 0, which on a boot-relative ticker reads as freshly set rather than as unset, so nothing counts as cached before the first resolve. The TTL is not a serialized value, so this only changes when the SDK re-resolves the hostname. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
9 tasks
📲 Install BuildsAndroid
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
HostnameCachestored an absolute expiry built fromSystem.currentTimeMillis()and compared it against a fresh reading of the same clock:A device time change therefore resized the 5 hour TTL. A backward step extended it by the size of the step; a forward step expired the cache early. Now a
Deadlineon aMonotonicTicker, so the TTL is the interval it claims to be.The expiry field also no longer starts at
0. On a boot-relative ticker0is a real and very recent instant, so a field left at0reads as freshly set rather than as unset — it now starts asDeadline.passed(ticker), so nothing counts as cached before the first resolve.The TTL is not a serialized value — it only decides when the SDK re-resolves the hostname — so this is not gated behind the v9 work.
💡 Motivation and Context
Audit finding §C6 from the clock-usage audit, which lists four wall-clock TTL/cleanup sites. This is one of them. See "Next steps" for where the other three went.
HostnameCacheTTL only)💚 How did you test it?
New test in
HostnameCacheTest: the hostname is re-resolved once the cache duration has elapsed, and not before, driven by advancing aTestMonotonicTickerrather than by sleeping for five hours. This path had no test at all previously — it was not reachable without a real clock.MainEventProcessorTest, the otherHostnameCacheconsumer, passes unchanged (45 tests).📝 Checklist
sendDefaultPIIis enabled.The package-private constructor gained a
MonotonicTickerparameter, which is what makes the TTL testable. The existingHostnameCache(long, Callable<InetAddress>)overload is unchanged, so existing callers and tests are unaffected.🔮 Next steps
The rest of §C6:
Sentry.javaand envelope rotation inCacheStrategy— both compare againstFile.lastModified(). A filesystem mtime is a wall-clock value, written by another process at a moment we never observed, so there is no monotonic quantity to compare it against; moving either to a ticker is not possible. Fixing them properly means not relying on mtimes at all (recording our own timestamp beside each file), which is a storage-format change well outside this item.java.util.Timer. That is a scheduling change rather than a TTL one and needs its own PR.🤖 Generated with Claude Code