Skip to content

ref(core): Measure the hostname cache TTL on a monotonic ticker (JAVA-579) - #6100

Merged
runningcode merged 4 commits into
mainfrom
no/java-579-c6-hostname-cache-ttl
Oct 15, 2026
Merged

runningcode merged 4 commits into
mainfrom
no/java-579-c6-hostname-cache-ttl

Conversation

@runningcode

@runningcode runningcode commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Previously the HostnameCache measured the TTL with System.currentTimeMillis() so when device time changes forward or backward it would extend the cache or expire the cache early.
The TTL is now a Deadline on the ticker from SentryOptions.getMonotonicTicker(). On Android that is elapsedRealtimeNanos(), so the TTL also counts deep sleep.

The deadline starts as Deadline.passed(ticker) rather than 0: on a boot-relative ticker 0 is a recent instant and would read as freshly cached. (this was previously a bug)

The TTL only decides when the hostname is re-resolved and is never serialized, so this is not gated on v9. (feel free to disagree)

Stacked on #6117, which moves the cache onto SentryOptions.

💡 Motivation and Context

One of the wall-clock TTL sites from audit finding:

💚 How did you test it?

Easier to test since we can advance the clock.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

No public API change; sentry.api is unchanged.

🔮 Next steps

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Sep 11, 2026

Copy link
Copy Markdown

JAVA-579

@sentry

sentry Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.60.0 (1) release

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode force-pushed the no/java-579-c6-hostname-cache-ttl branch from 1742189 to 378d9be Compare September 15, 2026 14:10
@runningcode
runningcode force-pushed the no/java-579-c6-hostname-cache-ttl branch 2 times, most recently from 2cd4aaf to fbec6c7 Compare October 14, 2026 07:43
@runningcode
runningcode changed the base branch from main to no/java-579-c6b-hostname-cache-on-options October 14, 2026 07:43
Base automatically changed from no/java-579-c6b-hostname-cache-on-options to main October 14, 2026 13:32
runningcode and others added 2 commits October 14, 2026 16:03
…-579)

HostnameCache stored an absolute expiry built from System.currentTimeMillis()
and compared it against a fresh reading of the same clock, so a device time
change resized the 5 hour TTL: a backward step extended it, a forward step
expired the cache early. It is now a Deadline on a MonotonicTicker.

The ticker comes from SentryOptions.getMonotonicTicker(), the same way
RateLimiter takes it, so on Android the TTL also counts time spent in deep
sleep. The cache names the ticker as its only collaborator rather than taking
the whole options. The LazyEvaluator that holds the cache defers reading the
ticker until after SentryAndroidOptions has overridden it.

The expiry no longer starts at 0: on a boot-relative ticker 0 is a real and
very recent instant, so it would read as freshly set rather than unset. It
starts as Deadline.passed(ticker) instead.

The TTL is not a serialized value, so this is not gated behind v9.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A superclass field initializer already dispatches to the subclass override
of getMonotonicTicker(), and SentryAndroidOptions returns a static
singleton, so building the cache eagerly would read the right ticker too.
The blocking hostname lookup is the only reason it is lazy.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/java-579-c6-hostname-cache-ttl branch from 8490310 to 9ff0dcf Compare October 14, 2026 14:15
runningcode and others added 2 commits October 14, 2026 16:19
…ctor

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…or testing

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread sentry/src/main/java/io/sentry/HostnameCache.java
Comment thread sentry/src/main/java/io/sentry/HostnameCache.java
@runningcode
runningcode marked this pull request as ready for review October 14, 2026 14:30
@runningcode runningcode added the sanity-check PR needs a lightweight review for obvious issues label Oct 14, 2026
@runningcode
runningcode merged commit d84944d into main Oct 15, 2026
72 of 73 checks passed
@runningcode
runningcode deleted the no/java-579-c6-hostname-cache-ttl branch October 15, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants