zjncs opened a new pull request, #4361:
URL: https://github.com/apache/hertzbeat/pull/4361
## What's changed
When a converge rule is deleted, renamed or disabled while its group cache
still holds firing alerts, `AlarmGroupReduce.sendGroupAlert` looks up the rule
and dereferences it without a null check
(`hertzbeat-alerter/.../AlarmGroupReduce.java:294`):
```java
AlertGroupConverge ruleConfig = groupDefines.get(cache.getGroupDefineName());
long repeatInterval = ruleConfig.getRepeatInterval() != null ...
```
`refreshGroupDefines` clears and reloads only enabled rules (called on every
rule add/update/delete from `AlertGroupConvergeServiceImpl`), but entries in
`groupCacheMap` keep their `groupDefineName`, so the lookup returns null for an
orphaned group.
Impact is worse than a one-off NPE: `runCheckAndSendGroups` iterates
`groupCacheMap.forEach` and the NPE aborts the whole iteration each cycle
(caught at the loop level), so **every group ordered after the orphaned one
stops receiving converged alerts, permanently, on every 1-second check cycle**
until restart.
The sibling method `shouldSendGroup` in the same file already null-checks
the identical lookup for `groupWait`/`groupInterval` and falls back to
defaults; this PR applies the same fallback to `repeatInterval`.
## Checklist
- [x] I have read the [Contributing Guidelines](CONTRIBUTING.md).
- [x] I have added a unit test for the change
(`whenRuleDeleted_firingGroupCacheMustStillBeDispatched` in
`AlarmGroupReduceTest`).
- [x] All tests pass locally (`mvn -pl hertzbeat-alerter -am test`: 474
tests, 0 failures).
---
**Verification**
- fail-before: the new test fails on master — the dispatch is aborted by
`java.lang.NullPointerException: Cannot invoke
"AlertGroupConverge.getRepeatInterval()" because "ruleConfig" is null` at
`AlarmGroupReduce.java:294`, logged by `runCheckAndSendGroups`' catch, and
`inhibitAlarm` is never invoked for the orphaned group
- pass-after: the orphaned firing group is dispatched with the default
repeat interval; all 7 `AlarmGroupReduceTest` tests and the full alerter module
suite pass (474 tests, 0 failures, 2 pre-existing skips)
**AI assistance disclosure**: the bug analysis, fix and test in this PR were
prepared with the help of an AI coding agent, and were verified locally by the
author as described above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]