Skip to content

fix(admin): keep persisted instance state when local heartbeat is missing (#7697) - #7863

Merged
Aias00 merged 1 commit into
apache:masterfrom
imDwAaY:fix/7697-instance-list-null-beat
Oct 20, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
imDwAaY:fix/7697-instance-list-null-beat

Conversation

@imDwAaY

@imDwAaY imDwAaY commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #7697.

Problem

GET /instance loads the persisted instance_info rows, then overrides each row with the node-local InstanceCheckService heartbeat cache. The lookup result is dereferenced without a null check.

InstanceCheckService.setup() (which calls fetchInstanceData() and fills the cache) only runs on the elected master, and /instance/** is not in the cluster forward-list. A follower therefore serves the list with an empty local cache and every row throws a NullPointerException, failing the whole page with a 500.

The same window exists on the master for rows persisted by another Admin writer or inserted after the local snapshot.

Change

  • When the local heartbeat entry is absent, keep the persisted instanceState and dateUpdated instead of failing. No fresh ONLINE state is fabricated.
  • last_heart_beat_time is not persisted in this branch, so the DB-mapped lastHeartBeatTime is 0. When it is non-positive, fall back to dateUpdated.getTime(); a positive persisted value is kept as-is. Once fix(admin): persist the instance last heartbeat time #7859 persists the column, the fallback stops triggering.
  • Nodes that do have a local heartbeat entry keep the existing override behavior, unchanged.

Tests

  • InstanceControllerTest#testQueryPluginsWithMissingHealthBeatInfo sends one page with two rows to cover both fallback cases: a missing entry with lastHeartBeatTime=0 (falls back to dateUpdated) and a persisted positive lastHeartBeatTime (kept as-is). It also asserts the response is 200.
  • The existing testQueryPlugins now asserts that local heartbeat values really override the persisted ones.

Validation

./mvnw -pl shenyu-admin -am -Dtest=InstanceControllerTest -DfailIfNoTests=false \
  -Djacoco.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true test
  • BUILD SUCCESS, Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
  • ./mvnw -o -pl shenyu-admin checkstyle:check passes.

Scope / follow-ups

  • No schema, mapper, service or API changes.
  • The two-node cluster E2E scenario from the issue is not included; the follower case is exactly "persisted rows + empty local cache" and is covered at the controller level.
  • After fix(admin): persist the instance last heartbeat time #7859 persists the instance last heartbeat time, the dateUpdated fallback no longer triggers.

…sing (apache#7697)

The instance list merged persisted rows with the node-local heartbeat cache and dereferenced a missing entry. Followers do not run InstanceCheckService.setup() and are not covered by the /instance/** forward list, so the whole page failed with an NPE. Keep the persisted state when the local entry is absent, and fall back to dateUpdated when lastHeartBeatTime has not been persisted yet.
@imDwAaY
imDwAaY force-pushed the fix/7697-instance-list-null-beat branch from c083625 to 4d50fb4 Compare October 19, 2026 15:19

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #7863 fix(admin): keep persisted instance state when local heartbeat is missing

Reviewed the change and the added test.

What's good

  • The NPE guard in InstanceController#queryPlugins correctly falls back to vo.getDateUpdated() when getInstanceHealthBeatInfo returns null. This keeps the persisted plugin/instance state from losing its lastHeartBeatTime just because the local heartbeat record is momentarily missing.
  • testQueryPluginsWithMissingHealthBeatInfo covers the new null path, asserting the persisted dateUpdated is used.

Non-blocking suggestions

  • Confirm whether sibling controllers that also call getInstanceHealthBeatInfo (or other paths that read instance health) can receive null and would benefit from the same fallback, so the behavior is consistent across the admin UI.
  • Minor: the fallback mixes two different time sources (heartbeat vs. entity update time); worth a one-line comment in the code explaining the precedence so future readers don't assume they are equivalent.

CI

Green. No failures.

Verdict

APPROVE — focused, low-risk fix with test coverage.

@Aias00
Aias00 merged commit 0de96a9 into apache:master Oct 20, 2026
55 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Instance list dereferences missing local heartbeat state on non-master Admin nodes

2 participants