Aias00 opened a new issue, #7436:
URL: https://github.com/apache/shenyu/issues/7436
## Is there an existing issue for this?
- [x] I searched existing open and closed issues.
## Current Behavior
HTTP long-polling's stale-admin cache recovery constructs a cache key with
the namespace twice and dereferences a missing entry.
The production `AbstractDataChangedListener.updateCache()` stores the
qualified key (for example `ns1_PLUGIN`) in `ConfigDataCache.group`. When a
gateway has a different MD5 and a newer modification timestamp,
`checkCacheDelayAndUpdate()` calls `buildCacheKey(serverCache.getNamespaceId(),
serverCache.getGroup())`. This produces `ns1_ns1_PLUGIN`.
`CACHE.get()` returns null, and the first `latest.getMd5()` raises a
`NullPointerException` before the admin can refresh its local namespace cache.
## Expected Behavior
If the gateway snapshot is newer than the admin's local cache,
refresh/re-read the correct namespace/group entry and return the appropriate
changed-group notification without failing the listener request.
## Steps To Reproduce
1. Enable HTTP config synchronization.
2. Populate the admin cache via the production `updateCache(PLUGIN, data,
"ns1")` path.
3. Submit a listener request for namespace `ns1` whose PLUGIN MD5 differs
and whose modification time is newer than the cached entry.
4. Observe an NPE at `HttpLongPollingDataChangedListener.java:261`.
This can occur when a gateway reconnects to a lagging admin node. The error
path is also directly reproducible by invoking `checkCacheDelayAndUpdate` with
a cache entry created by the actual production `updateCache` method.
Observed local reproduction:
```text
production group=ns1_PLUGIN; recovery lookup=ns1_ns1_PLUGIN
java.lang.NullPointerException: Cannot invoke ConfigDataCache.getMd5()
because latest is null
at HttpLongPollingDataChangedListener.checkCacheDelayAndUpdate(...:261)
```
## Environment
ShenYu `2.7.2-SNAPSHOT`, `master` at
`67596c1d228b62da75cd0a0ecb47d0ac5d995384`, Java 17, HTTP sync enabled.
## Location And Impact
-
[AbstractDataChangedListener.java:327](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/AbstractDataChangedListener.java#L327):
stores the qualified cache key as the group.
-
[HttpLongPollingDataChangedListener.java:257](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/http/HttpLongPollingDataChangedListener.java#L257):
qualifies it again.
-
[HttpLongPollingDataChangedListener.java:261](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/http/HttpLongPollingDataChangedListener.java#L261):
dereferences the null lookup result.
Severity: Medium. Confidence: high. Poll requests against a lagging admin
can repeatedly fail instead of executing the recovery logic; other periodic
cache refreshes may eventually recover the node. The gateway retries listener
failures, then backs off for five minutes after ten failures.
## Suggested Fix And Regression Coverage
Use one consistent representation for the bare configuration group and the
qualified cache key. Avoid applying `buildCacheKey()` to an already qualified
group. Check the concurrent re-read and post-refresh branches too.
Add a regression that populates the cache via `updateCache()` rather than
manually storing `ConfigDataCache("PLUGIN", ...)`, then exercises a
newer-client timestamp. Cover concurrent cache replacement and
unchanged/newer-admin branches.
## Validation And Related Issues
- Compiled the current listener/cache source and reproduced the NPE with a
Mockito real-method listener and a production-created cache entry.
- Existing
`AbstractDataChangedListenerTest,HttpLongPollingDataChangedListenerTest`: 42
tests passed with zero failures. Existing recovery tests use bare group names,
which differ from production construction.
- An independent verifier confirmed endpoint/gateway reachability,
reproduction, and duplicate checks.
- No multi-node gateway/admin integration deployment was run.
- #6523, #6891, #6504, #6662, and #6663 describe different HTTP sync
lookup/refresh behavior; this issue concerns double qualification in the
stale-admin recovery branch.
--
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]