Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Dubbo @Reference retries=0 Configuration Bug in Version 2.6.2

Tech May 17 2

A production incident revealed duplicate data creation: a single save operation resulted in three database records. Investigation traced the issue to inconsistent retry behavior between Dubbo’s XML and annotation-based configuration for retries = 0.

In XML configuration, the following disables retries as expected:

<dubbo:reference id="testService" interface="heiidea.trade.service.sdk.interfice.TestService" retries="0"/>

However, using the @Reference annotation with identical semantics fails:

@Reference(retries = 0)
private TestService testService;

Debugging through the invocation chain — from InvokerInvocationHandler.invoke()MockClusterInvoker.invoke()AbstractClusterInvoker.invoke()FailoverClusterInvoker.doInvoke() — revealed that retries resolved to null when set via @Reference, causing fallback to the default value of 2. Combined with the initial call, this produced three total invocations.

In contrast, the XML parser correct parsed retries="0" as integer 0, resulting in exactly one invocation (no retries).

Root Cause Analysis

The discrepancy stems from how attribute values are adapted during bean construction:

  • Annotation path: ReferenceAnnotationBeanPostProcessor processes @Reference fields. During buildReferenceBean(), the raw retries = 0 is preserved initially. However, later in preConfigureBean(), AnnotationPropertyValuesAdapter invokes AnnotationUtils.getAttributes(), which internally calls nullSafeEquals(attributeValue, defaultValue). Since the default retries value is 2, and 0 == 2 evaulates to false, this should retain the attribute. But in Dubbo 2.6.2, the logic incorrectly treats 0 as equivalent to the default when comparing against null or unconfigured state — ultimately omitting retries from the final actualAttributes map. Consequently, getRetries() returns null, triggering fallback to 2.

  • XML path: The DubboNamespaceHandler parses <dubbo:reference> by reflecting over ReferenceBean’s setter methods (e.g., setRetries(int)). It directly assigns the parsed integer 0 without equality-based filtering, preserving the explicit zero value.

Behavioral Summary

Configuration Style retries not specified retries = 0 retries = -1
XML (<dubbo:reference>) 2 retries (3 total calls) 0 retries (1 total call) 0 retries
Annotation (@Reference) 2 retries 2 retries (due to null fallback) 0 retries

To guarantee zero retries with annotations in affected versions, use retries = -1. For idempotent operations like writes, this avoids unintended side effects. Upgrading to Dubbo ≥2.7.3 resolves the isue: the annotation processor now consistently treats 0 as an explicit override rather than discarding it during attribute adaptation.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.