Repository navigation
Conversation
|
Verification complete — I've confirmed the repo state, the three pre-existing unguarded walks, the test helpers the new tests rely on, and found the same latent bug in six other files. Here is my review. Review: fix(broker): bound root-cause traversal to survive cyclic exception chainsSummaryThe PR bounds three
|
| Location | Guard today |
|---|---|
RocketMQClientProvider.java:426 (rootMessage) |
none |
RocketMQClusterProvider.java:238 (rootMessage) |
none |
RocketMQConsumerDiagnosticsProvider.java:133 (rootMessage) |
none |
ApacheAclReadService.java:85 (rootMessage) |
direct self-cycle only |
RocketMQMessageProvider.java:501 (isTraceTopicAbsent) |
direct self-cycle only |
SettingsService.java:456 (hasCause) |
none |
AbstractPrometheusCompatibleMetricsSource.java:407 |
none |
The provider-side rootMessage methods are the same user-facing 502-message hot paths as the three fixed ones. Fixing three copies and leaving five+ creates two coexisting idioms for the same problem. I'd suggest either fixing all sites in this PR, or (better) extracting one shared helper, e.g. org.apache.rocketmq.studio.common.util.RootCauses.rootMessage(Throwable) plus a bounded-iteration variant for the hasCause/isTraceTopicAbsent walks, and migrating every call site. That also removes the now-quadruplicated message == null ? getClass().getSimpleName() : message tail.
Minor observations
MqAdminExtFactory.java— the addedimport java.util.Set;lands betweenMapandObjects, breaking the existing alphabetical order. Trivial.- When the loop exits on a repeat, the reported message comes from the first repeated exception — arbitrary in a cycle, but acceptable since a cycle has no true root.
- Optional hardening: an identity set doesn't bound a pathological
getCause()override returning fresh instances per call; a small max-depth cap (e.g. 64) would cover that too. Low priority. - The
MqClientPoolseams are fine and consistent with the existingnewAdminseam inMqAdminExtFactory.java:173.
Tests
Good approach overall: two-exception cycle + assertTimeoutPreemptively is the right tool, and the unfixed-code failure claims are consistent with how CompletableFuture.join() ignores interrupts. Gaps:
- No cyclic-chain test for the client start-failure paths —
createPullConsumer/createProducercatch blocks (andMqAdminExtFactory.createAndStart) also callrootMessage; adoThrow(cyclic).when(producer).start()case would cover them. withPullConsumercyclic path is untested (onlywithProducer); both route through the sameexecute, so low risk.- A direct self-cycle case would pin the old-behavior equivalence.
Verdict: the three fixes are correct and well-tested, but please (1) confirm the @Test annotations are intact in the real patch, and (2) either extend the guard to the remaining unguarded sites or land a shared utility so the class of bug is closed out, not three instances of it.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR fixes a real latent infinite loop bug where cyclic exception chains (e.g., A caused by B, B caused by A) would cause rootMessage() to hang indefinitely in three locations: RegistryProbeRunner, MqAdminExtFactory, and MqClientPool. The old guard (cause.getCause() != cause) only caught direct self-cycles, not two-or-more-node cycles.
Overall: LGTM — excellent bug fix with thorough tests.
Strengths
- Correct use of
IdentityHashMap-backedSet<Throwable>— identity-based tracking is essential here sinceThrowable.equals()is not reliable for cycle detection - Tests construct actual cyclic chains and use
assertTimeoutPreemptivelyto verify the fix prevents hangs — well-designed verification - New
newPullConsumer/newProducerseams inMqClientPoolenable proper unit testing with stubs — good testability improvement - Clear PR description explaining the root cause, affected code paths, and testing methodology
- The
MAX_CAUSE_DEPTH = 64belt-and-suspenders limit is a good defensive measure even with cycle detection
Minor Observations
-
[Info] The
Set<Throwable> seen = Collections.newSetFromMap(new IdentityHashMap<>())pattern is repeated 3 times. Consider a small utility likeIdentityHashSet.newSet()if more cycle-guarding code is added. -
[Info] In
MqClientPool.createPullConsumer(), thenewPullConsumer(rpcHook)seam is great for testing. ThePULL_CONSUMER_GROUPconstant is now only referenced insidenewPullConsumer(), which is clean.
Automated review by github-manager-bot
447430c to
30a80c0
Compare
Summary
rootMessagecause-chain walk inRegistryProbeRunner(which had no cycleguard),
MqAdminExtFactoryandMqClientPool(whosecause.getCause() != causeguard onlycatches a direct self-cycle) with an
IdentityHashMap-backed visited set.request/worker thread on every admin call or registry probe whose underlying exception chain
is cyclic.
protected newPullConsumer/newProducerseams inMqClientPool(mirroring theexisting
MqAdminExtFactory.newAdminseam) so the pool can be unit-tested with stub clients.Why
rootMessagewalksThrowable.getCause()to build user-facing 502 messages. Nothing in theRocketMQ client or remoting stack guarantees cause chains are acyclic (custom wrappers,
initCause, serialization frameworks can create cycles), so an unbounded walk is a latentinfinite loop on the hot path of every live admin call and every concurrent registry probe.
RegistryProbeRunner.rootMessageruns inside the probe executor; a hang there also stalls thelistRegistryClustersrequest thread that joins on the probe result.Testing
mvn -Dtest=ClusterServiceRegistryTest,MqAdminExtFactoryTest,MqClientPoolTest test:Tests run: 21, Failures: 0, Errors: 0, Skipped: 0 (6 + 14 + 1).
probeAllShouldSurviveCyclicCauseChainWithoutHangingTestandexecuteShouldSurviveCyclicCauseChainWithoutHangingeach hang until the 10sassertTimeoutPreemptivelydeadline (Tests run: 20, Failures: 2, Errors: 0).MqClientPoolTestcase requires the newnewProducerseam, so its unfixed counterpartis the identical unguarded
rootMessageinMqClientPool.Verification on Linux
Ubuntu 22.04, OpenJDK 21.0.12, Maven 3.6.3, rebased onto
rocketmq-studio6c24d2ed, run fromserver/:Both failures are
AuthCorsIntegrationTest, which fails on the branch head without thischange too (the test still stubs the pre-#2895
isAuthenticatedcall). #4217 repairs it.Every other test, including the ones added here, passes.