fix(polaris): prevent nil pointer panic when route rules don't match#3313
Open
cvictory wants to merge 1 commit into
Open
fix(polaris): prevent nil pointer panic when route rules don't match#3313cvictory wants to merge 1 commit into
cvictory wants to merge 1 commit into
Conversation
…3303) When Polaris route rules don't match (e.g., uid-only rules without discovery fallback), Route() could return an empty invoker slice, causing nil pointer panic in downstream cluster invokers. Add empty-result guard after ProcessRouters: if no invokers match the routed instances, fall back to original invokers with a warning log instead of returning an empty slice. Closes #3303
|
AlexStocks
reviewed
Apr 29, 2026
| } | ||
| } | ||
|
|
||
| if len(ret) == 0 { |
Contributor
There was a problem hiding this comment.
[P0] len(ret)==0 时直接回退到 invokers 会绕过真正生效的 Polaris 路由规则。ret 为空并不只代表“实例 ID 映射不上”,也可能是路由规则故意把当前请求全部过滤掉;这时正确行为应该是返回空结果并让上层按“无可用 provider”处理,而不是把原始 invokers 全部放回来继续发流量。现在的实现会把本应被路由规则拦掉的请求重新打到 provider 上,属于治理语义错误。
AlexStocks
reviewed
Apr 29, 2026
| } | ||
| } | ||
|
|
||
| if len(ret) == 0 { |
Contributor
There was a problem hiding this comment.
[P0] len(ret)==0 时直接回退到 invokers 会绕过真正生效的 Polaris 路由规则。ret 为空并不只代表“实例 ID 映射不上”,也可能是路由规则故意把当前请求全部过滤掉;这时正确行为应该是返回空结果并让上层按“无可用 provider”处理,而不是把原始 invokers 全部放回来继续发流量。现在的实现会把本应被路由规则拦掉的请求重新打到 provider 上,属于治理语义错误。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Bug
RouteRuleNotMatchfollowed by nil pointer panic.Route()incluster/router/polaris/router.goreturns an empty invoker slice whenProcessRoutersreturns instances that don't map to any known invoker. The empty slice propagates to cluster invokers (failfast, failover, etc.) which accessinvokers[0], causing nil pointer panic.Fix
After building the result from
ProcessRoutersresponse, if the result is empty (no matching invokers), log a warning and return the original invokers as a safe fallback. This follows the same defensive pattern used in 5 other error paths in the same method.Changed files:
cluster/router/polaris/router.go— 4-line empty-result guardcluster/router/polaris/router_test.go— 7 new regression tests with mock infrastructureVerification
go vet: cleango build: cleanTestRouteRuleNotMatchFallbackToOriginalInvokers— non-matching instances → fallbackTestRouteEmptyProcessRoutersResultFallbackToOriginalInvokers— empty result → fallbackTestRouteHappyPathReturnsMatchedInvokers— matching instances → filtered (behavior preserved)Closes #3303