HY-love-sleep opened a new pull request, #7211:
URL: https://github.com/apache/shenyu/pull/7211
## What
`TarsPlugin` picks one of the proxies of the cached upstream at random:
```java
int index =
ThreadLocalRandom.current().nextInt(tarsInvokePrxList.getTarsInvokePrxList().size());
```
When a path was never initialized the cache loader returns an empty proxy
list, so `nextInt(0)`
throws `IllegalArgumentException` and every request routed to that path
fails with a raw 500
instead of a proper error response. The plugin now answers with
`CANNOT_FIND_HEALTHY_UPSTREAM_URL` — the same result the divide and
websocket plugins already
return for an empty upstream list — and logs the offending path.
## Why
Closes #6652.
## Tests
* `TarsPluginTest#testTarsPluginWithEmptyProxyList` (new): routes a request
to a path that was
never initialized and asserts the plugin completes with the error response
instead of throwing.
Two pre-existing tests in the same class asserted the
`IllegalArgumentException` above, i.e. they
could only pass **while this bug was present**:
* `testTarsPluginWithArgumentTypeMissMatch` → now asserts the error response
instead of an escaped
exception.
* `testTarsPluginNormal` → now exercises the invocation path and asserts
`RPC_RESULT` is written
back. Its `Method#invoke` stub never matched the varargs call, so that
part of the test was dead
code until the plugin actually reached it.
## Verified
* `./mvnw -pl shenyu-plugin-tars -am test
-Dtest='TarsPluginTest,TarsPluginDataHandlerTest,TarsMetaDataHandlerTest,ApplicationConfigCacheTest,PrxInfoUtilTest'`
→ **Tests run: 24, Failures: 0, Errors: 0**
* checkstyle: 0 violations
--
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]