Repository navigation
fix: Non-default HTTP retry backoff strategies cannot be selected - #6529
Conversation
- Add HttpRetryBackoffSpecEnumTest for acquireByName coverage - Add retryBackOffSpec getter/setter test in DivideRuleHandleTest - Add DividePluginTest assertions for HTTP_RETRY_BACK_OFF_SPEC attribute - Fix plugin_handle sort conflict: retryBackOffSpec sort 0→1 - Disable custom dict entry (enabled 1→0) in all SQL dialects - Remove CUSTOM_BACKOFF enum value and CustomRetryStrategy class - Remove CUSTOM_BACKOFF case from AbstractHttpClientPlugin switch
8d985ef to
432de3b
Compare
Aias00
left a comment
There was a problem hiding this comment.
Reviewed #6529 — fixes #6464. The root-cause analysis is correct and the fix is sound: Constants.HTTP_RETRY_BACK_OFF_SPEC was "default", used as the exchange attribute key, so nothing ever wrote under it and AbstractHttpClientPlugin always fell back to DefaultRetryStrategy, leaving fixed/exponential/custom unreachable. Renaming the key to "httpRetryBackOffSpec", adding DivideRuleHandle.retryBackOffSpec, populating it in DividePlugin, switching the switch to HttpRetryBackoffSpecEnum, and replacing CustomRetryStrategy's return null with an explicit Mono.error all address the reported defects. Backward compatibility is fine: existing rule-handle JSON lacks the new field, Gson leaves it at the field initializer ("default"), so existing configs keep routing to DefaultRetryStrategy. DB IDs are collision-free and consistent across all 6 init dialects and 5 upgrade scripts. The constant-value change only affects an in-memory attribute key (no persisted JSON key changes; only 3 Java consumers).
Non-blocking, but worth addressing before merge:
-
(should_fix) No regression test for the actual bug.
DivideRuleHandleTest.testGetterSettercovers every sibling field exceptretryBackOffSpec;DividePluginTestdoesn't assertConstants.HTTP_RETRY_BACK_OFF_SPECis placed into the exchange fromruleHandle.getRetryBackOffSpec();RetryStrategyTestexercises strategies in isolation but not the selection switch inAbstractHttpClientPlugin.execute. The whole point of the PR — that a configured non-default spec is actually selected — is untested, so #6464 can regress silently. Suggested additions: (a) aDividePluginTestcase asserting the attribute is set from the rule handle (mirroring theHTTP_RETRY/RETRY_STRATEGYputs); (b)HttpRetryBackoffSpecEnumTestcoveringacquireByNamefor each name + null + unknown →DEFAULT_BACKOFF(every other enum in the package has one); (c) extendtestGetterSetterto set/assertretryBackOffSpec. -
(nit) The new
retryBackOffSpecplugin_handlerow usessort=0, identical toretryStrategy, so the two fields' admin-UI order is non-deterministic. Give it a distinct sort (e.g. 1). -
(nit / open question)
CustomRetryStrategynow throwsUnsupportedOperationException("Please implement CustomRetryStrategy via SPI"). Returning an explicit error is a clear improvement overreturn null, but I couldn't find an SPI/registry for this strategy in the diff or undershenyu-plugin-httpclient. If no extension point exists, consider hidingcustomfrom theRETRY_BACKOFF_SPECdict until one does, since selecting it today always yields a 503.
Note: PR is in BEHIND merge state (needs a rebase onto master before merge).
…ies_cannot_be_selected
…ies_cannot_be_selected
|
Solid, well-tested fix — the string→enum switch in One minor inconsistency: the SQL scripts add a |
…ies_cannot_be_selected
…ff_strategies_cannot_be_selected' into fix/Non_default_HTTP_retry_backoff_strategies_cannot_be_selected
Aias00
left a comment
There was a problem hiding this comment.
Summary
This PR makes the HTTP retry backoff strategy selectable via DivideRuleHandle.retryBackOffSpec (default / fixed / exponential) instead of the previously hard-wired, non-selectable behavior.
What is correct
DivideRuleHandlegains aretryBackOffSpecfield (defaultHttpRetryBackoffSpecEnum.getDefault()), andequals/hashCode/toStringare updated consistently so handle serialization round-trips correctly.DividePlugin.doExecuteputsHTTP_RETRY_BACK_OFF_SPECinto the exchange attributes (defaulting togetDefault()when empty), andAbstractHttpClientPlugin.executenow resolves the strategy viaHttpRetryBackoffSpecEnum.acquireByName(...)instead of a brittle stringswitch. Unknown/empty values fall back toDEFAULT_BACKOFF.- The dead
CustomRetryStrategyclass (whoseexecutereturnednull) and theCUSTOM_BACKOFFenum value are removed.AbstractHttpClientPluginno longer references them. - DB changes are complete:
plugin_handle+shenyu_dictrows forretryBackOffSpecare added to mysql/ob/og/oracle/pg init scripts and to the2.7.0-upgrade-2.7.1-*upgrade scripts, plus the h2 test schema. - Tests added:
HttpRetryBackoffSpecEnumTest,DivideRuleHandleTestgetter/setter, andDividePluginTestasserting both the explicit value and the default attribute are propagated.
Verification
- A repo-wide search for
CustomRetryStrategy/CUSTOM_BACKOFFonmasterreturns only the two files this PR itself modifies/deletes (CustomRetryStrategy.java,AbstractHttpClientPlugin.java,HttpRetryBackoffSpecEnum.java). No other module references the removed symbols, so the deletion does not leave dangling compiles. Constants.HTTP_RETRY_BACK_OFF_SPECwas renamed from the misleading literal"default"to"httpRetryBackOffSpec"; both producer (DividePlugin) and consumer (AbstractHttpClientPlugin) use the same constant, and the attribute is a per-request exchange key (never persisted), so there is no external/serialized contract break.
Non-blocking suggestions
- The
2.7.0-upgrade-2.7.1-*.sqlinserts are plainINSERTs (notINSERT IGNORE). This matches the surrounding entries in those scripts, but if an operator re-runs an upgrade script it would now duplicate-key. Worth a follow-up to make the new rows idempotent, consistent with how other ShenYu upgrades eventually converge. - Please confirm the admin metadata-sync path exposes
retryBackOffSpecas a configurable field for the divide plugin so operators can actually select it (the schema is in place; this is just the admin UI/metadata wiring).
Conclusion
Approved. The implementation is coherent, the removal is safe, and the DB coverage is thorough across all supported dialects.
gh pr review 6529 --repo apache/shenyu --approve --body-file review_6529.md…ies_cannot_be_selected
dengliming
left a comment
There was a problem hiding this comment.
loadBalancerFactoryMockedStatic is being closed twice here: once explicitly after the mocked call path, and then again after the assertThrows branch. That double-close triggers Mockito's static mock lifecycle error and is the direct cause of the failing CI job.
Could we either remove the second close() or wrap this mock in try-with-resources so it is guaranteed to be closed exactly once?
…ies_cannot_be_selected
…ache#6529) * fix: Non-default HTTP retry backoff strategies cannot be selected * fix: add tests, fix sort conflict, and hide custom backoff strategy - Add HttpRetryBackoffSpecEnumTest for acquireByName coverage - Add retryBackOffSpec getter/setter test in DivideRuleHandleTest - Add DividePluginTest assertions for HTTP_RETRY_BACK_OFF_SPEC attribute - Fix plugin_handle sort conflict: retryBackOffSpec sort 0→1 - Disable custom dict entry (enabled 1→0) in all SQL dialects - Remove CUSTOM_BACKOFF enum value and CustomRetryStrategy class - Remove CUSTOM_BACKOFF case from AbstractHttpClientPlugin switch * test: add tests * fix: fix tests * trigger CI * fix: delete `custom` in shenyu.dict * fix: fix tests --------- Co-authored-by: Liming Deng <[email protected]>
Fixes #6464
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.