Skip to content

Commit a403884

Browse files
runningcodeclaude
andcommitted
ref(core): Stop closing the hostname cache
The cache's executor is a single daemon thread with allowCoreThreadTimeOut(true) and a 30 second keep-alive, so it self-terminates once idle and never holds up process exit. close() was switching off something that switches itself off. Scopes.close() already leaves the timer executor running for this reason. Dropping it removes the reason SentryOptions.resetHostnameCache() existed. That method was only there because MainEventProcessor closed a cache the options own, which a re-init with the same options object would then keep handing out shut down. Nothing closes the cache now, so nothing has to undo it. MainEventProcessor no longer implements Closeable, and no longer memoizes the cache either: the options build it on first use, so the field and ensureHostnameCache() were duplicating LazyEvaluator. Both removed methods are on @ApiStatus.Internal types. SentryClientTest's `when client is closed, hostname cache is closed` went with them; it asserted isClosed() on a processor that had never resolved a hostname, which returned true because the cache was still null. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7a59f20 commit a403884

4 files changed

Lines changed: 1 addition & 34 deletions

File tree

‎sentry/api/sentry.api‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3919,7 +3919,6 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig {
39193919
public fun isTraceSampling ()Z
39203920
public fun isTracingEnabled ()Z
39213921
public fun merge (Lio/sentry/ExternalOptions;)V
3922-
public fun resetHostnameCache ()V
39233922
public fun setAppStartExtender (Lio/sentry/IAppStartExtender;)V
39243923
public fun setAttachServerName (Z)V
39253924
public fun setAttachStacktrace (Z)V

‎sentry/src/main/java/io/sentry/MainEventProcessor.java‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public final class MainEventProcessor implements EventProcessor {
2121
private final @NotNull SentryOptions options;
2222
private final @NotNull SentryThreadFactory sentryThreadFactory;
2323
private final @NotNull SentryExceptionFactory sentryExceptionFactory;
24-
private volatile @Nullable HostnameCache hostnameCache = null;
2524

2625
public MainEventProcessor(final @NotNull SentryOptions options) {
2726
this.options = options;
@@ -160,16 +159,7 @@ private void setServerName(final @NotNull SentryBaseEvent event) {
160159
}
161160

162161
if (options.isAttachServerName() && event.getServerName() == null) {
163-
ensureHostnameCache();
164-
if (hostnameCache != null) {
165-
event.setServerName(hostnameCache.getHostname());
166-
}
167-
}
168-
}
169-
170-
private void ensureHostnameCache() {
171-
if (hostnameCache == null) {
172-
hostnameCache = options.getHostnameCache();
162+
event.setServerName(options.getHostnameCache().getHostname());
173163
}
174164
}
175165

‎sentry/src/main/java/io/sentry/SentryOptions.java‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,17 +3157,6 @@ public void setDateProvider(final @NotNull SentryDateProvider dateProvider) {
31573157
return hostnameCache.getValue();
31583158
}
31593159

3160-
/**
3161-
* Discards the cached instance, so that the next {@link #getHostnameCache()} builds a new one.
3162-
*
3163-
* <p>Called after the cache has been closed, because these options outlive a restart and a closed
3164-
* cache can no longer resolve anything.
3165-
*/
3166-
@ApiStatus.Internal
3167-
public void resetHostnameCache() {
3168-
hostnameCache.resetValue();
3169-
}
3170-
31713160
/**
31723161
* Adds a ICollector.
31733162
*

‎sentry/src/test/java/io/sentry/SentryOptionsTest.kt‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,15 +1359,4 @@ class SentryOptionsTest {
13591359
assertThat(options.hostnameCache).isSameInstanceAs(cache)
13601360
assertThat(cache.getProperty<MonotonicTicker>("ticker")).isSameInstanceAs(ticker)
13611361
}
1362-
1363-
@Test
1364-
fun `resetHostnameCache discards the cached instance`() {
1365-
val options = optionsWithTicker(TestMonotonicTicker())
1366-
val cache = options.hostnameCache
1367-
1368-
options.resetHostnameCache()
1369-
1370-
assertThat(options.peekHostnameCache()).isNull()
1371-
assertThat(options.hostnameCache).isNotSameInstanceAs(cache)
1372-
}
13731362
}

0 commit comments

Comments
 (0)