Skip to content

Commit 2cbce6a

Browse files
authored
SNTConfigurator: skip override-file watcher when overrides disabled (#936)
The DEBUG-only override-file watcher was dispatched onto a global queue unconditionally and held `self` in a polling loop. Under xctest's `--runs_per_test`, the worker block survived bundle teardown and aborted on `objc_msgSend` to a now-unloaded class, manifesting as a 1/25 flake in DaemonConfigBundleTest. Gate the dispatch on the same xctest+ENABLE_CONFIG_OVERRIDES check that already short-circuits applyOverrides:, lifted into a shared overridesEnabled helper so both call sites can't drift.
1 parent 801d6c9 commit 2cbce6a

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

Source/common/SNTConfigurator.mm

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,17 +2221,24 @@ - (NSRegularExpression*)expressionForPattern:(NSString*)pattern {
22212221
return [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:NULL];
22222222
}
22232223

2224-
- (void)applyOverrides:(NSMutableDictionary*)forcedConfig {
2225-
// Overrides should only be applied under debug builds.
2224+
// Whether the debug-only config-override-file mechanism is active in this process.
2225+
// Off by default under xctest so override values don't leak into tests; opt in per
2226+
// test with `bazel test --test_env=ENABLE_CONFIG_OVERRIDES=1 ...`.
2227+
- (BOOL)overridesEnabled {
22262228
#ifdef DEBUG
2227-
if ([[[NSProcessInfo processInfo] processName] isEqualToString:@"xctest"] &&
2228-
![[[NSProcessInfo processInfo] environment] objectForKey:@"ENABLE_CONFIG_OVERRIDES"]) {
2229-
// By default, config overrides are not applied when running tests to help
2230-
// mitigate potential issues due to unexpected config values. This behavior
2231-
// can be overriden if desired by using the env variable: `ENABLE_CONFIG_OVERRIDES`.
2232-
//
2233-
// E.g.:
2234-
// bazel test --test_env=ENABLE_CONFIG_OVERRIDES=1 ...other test args...
2229+
if (![[[NSProcessInfo processInfo] processName] isEqualToString:@"xctest"]) {
2230+
return YES;
2231+
} else {
2232+
return
2233+
[[[NSProcessInfo processInfo] environment] objectForKey:@"ENABLE_CONFIG_OVERRIDES"] != nil;
2234+
}
2235+
#else
2236+
return NO;
2237+
#endif
2238+
}
2239+
2240+
- (void)applyOverrides:(NSMutableDictionary*)forcedConfig {
2241+
if (![self overridesEnabled]) {
22352242
return;
22362243
}
22372244

@@ -2251,7 +2258,6 @@ - (void)applyOverrides:(NSMutableDictionary*)forcedConfig {
22512258
forcedConfig[key] = [self expressionForPattern:pattern];
22522259
}
22532260
}
2254-
#endif
22552261
}
22562262

22572263
- (id)overriderValue:(id)value forKey:(NSString*)key {
@@ -2304,9 +2310,11 @@ - (void)startWatchingDefaults {
23042310
name:NSUserDefaultsDidChangeNotification
23052311
object:nil];
23062312
#ifdef DEBUG
2307-
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
2308-
[self watchOverridesFile];
2309-
});
2313+
if ([self overridesEnabled]) {
2314+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
2315+
[self watchOverridesFile];
2316+
});
2317+
}
23102318
#endif
23112319
}
23122320

0 commit comments

Comments
 (0)