Skip to content

Commit

Permalink
HealthNotifier: fix dependent messages handling (#573)
Browse files Browse the repository at this point in the history
Fixes tailscale/corp#24582

Android port of tailscale/corp#24719. We were not clearing dependency warnings when a new warning was added which was listed as a dependency of a pre-existing warning. For instance, if `dns-read-os-config-failed` is added to the warnings before `network-status` is added, we were ignoring the dependency by not removing `dns-read-os-config-failed` upon adding `network-status`. This PR addresses that.

Signed-off-by: Andrea Gottardo <[email protected]>
  • Loading branch information
agottardo authored Nov 26, 2024
1 parent 91a1316 commit 61c7c3c
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ class HealthNotifier(
val warningsBeforeAdd = currentWarnings.value
val currentWarnableCodes = warnings.map { it.WarnableCode }.toSet()
val addedWarnings: MutableSet<UnhealthyState> = mutableSetOf()
val removedByNewDependency: MutableSet<UnhealthyState> = mutableSetOf()
val isWarmingUp = warnings.any { it.WarnableCode == "warming-up" }

/// Checks if there is any warning in `warningsBeforeAdd` that needs to be removed because the new warning `w`
/// is listed as a dependency of a warning already in `warningsBeforeAdd`, and removes it.
fun dropDependenciesForAddedWarning(w: UnhealthyState) {
for (warning in warningsBeforeAdd) {
warning.DependsOn?.let {
if (it.contains(w.WarnableCode)) {
removedByNewDependency.add(warning)
}
}
}
}

for (warning in warnings) {
if (ignoredWarnableCodes.contains(warning.WarnableCode)) {
continue
Expand All @@ -81,6 +94,7 @@ class HealthNotifier(
} else if (!isWarmingUp) {
TSLog.d(TAG, "Adding health warning: ${warning.WarnableCode}")
this.currentWarnings.set(this.currentWarnings.value + warning)
dropDependenciesForAddedWarning(warning)
if (warning.Severity == Health.Severity.high) {
this.sendNotification(warning.Title, warning.Text, warning.WarnableCode)
}
Expand All @@ -89,7 +103,7 @@ class HealthNotifier(
}
}

val warningsToDrop = warningsBeforeAdd.minus(addedWarnings)
val warningsToDrop = warningsBeforeAdd.minus(addedWarnings).union(removedByNewDependency)
if (warningsToDrop.isNotEmpty()) {
TSLog.d(TAG, "Dropping health warnings with codes $warningsToDrop")
this.removeNotifications(warningsToDrop)
Expand Down

0 comments on commit 61c7c3c

Please sign in to comment.