Repository navigation
Commit 15d64a4
authored
core: Reject retryThrottling without maxTokens or tokenRatio clearly (grpc#13131)
## Problem
`ServiceConfigUtil.getThrottlePolicy()` reads the two required fields of
`retryThrottling` with `JsonUtil.getNumberAsDouble(...).floatValue()`.
When
either field is missing, `getNumberAsDouble` returns null and the call
fails
with an NPE:
Cannot invoke "java.lang.Double.floatValue()" because the return value
of
"io.grpc.internal.JsonUtil.getNumberAsDouble(java.util.Map, String)" is
null
`ScParser` catches it and the channel reports `UNKNOWN: failed to parse
service config`, but the cause doesn't say which field is missing. This
was
noted in the code as `TODO(dapengzhang0): check if this is null.`
## Fix
Check both fields with `checkNotNull(..., "<field> cannot be empty")`,
the
same message used for the required `retryPolicy` and `hedgingPolicy`
fields
in `ManagedChannelServiceConfig`. The exception type is still the NPE
that
`ScParser` already handles, so the only change is a clearer message.
## Testing
Added `getThrottlePolicy_failOnMissingMaxTokens` and
`getThrottlePolicy_failOnMissingTokenRatio` to `ServiceConfigUtilTest`.
Both
failed before the fix with the NPE above.1 parent 14a27ad commit 15d64a4
2 files changed
Lines changed: 28 additions & 3 deletions
File tree
- core/src
- main/java/io/grpc/internal
- test/java/io/grpc/internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
117 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
117 | 139 | | |
118 | 140 | | |
119 | 141 | | |
| |||
0 commit comments