Skip to content

Commit c8facc5

Browse files
356082462chickenlj
authored andcommitted
修复注册中心域名解析导致的单点问题 (#4293)
Fix #2545
1 parent 6702cbd commit c8facc5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Registry getRegistry(URL url) {
8585
url = url.setPath(RegistryService.class.getName())
8686
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
8787
.removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
88-
String key = url.toServiceString();
88+
String key = url.toServiceStringWithoutResolving();
8989
// Lock the registry access process to ensure a single instance of the registry
9090
LOCK.lock();
9191
try {

dubbo-registry/dubbo-registry-api/src/test/java/com/alibaba/dubbo/registry/support/AbstractRegistryFactoryTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.alibaba.dubbo.registry.NotifyListener;
2222
import com.alibaba.dubbo.registry.Registry;
2323
import com.alibaba.dubbo.registry.RegistryFactory;
24-
2524
import junit.framework.Assert;
2625
import org.junit.Test;
2726

@@ -87,9 +86,15 @@ public void testRegistryFactoryCache() throws Exception {
8786

8887
@Test
8988
public void testRegistryFactoryIpCache() throws Exception {
90-
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233"));
91-
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"));
92-
Assert.assertEquals(registry1, registry2);
89+
String hostName = NetUtils.getLocalAddress().getHostName();
90+
String ip = NetUtils.getLocalAddress().getHostAddress();
91+
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + hostName + ":2233"));
92+
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + ip + ":2233"));
93+
if (hostName.equals(ip)) {
94+
Assert.assertEquals(registry1, registry2);
95+
} else {
96+
Assert.assertNotSame(registry1, registry2);
97+
}
9398
}
9499

95100
@Test

0 commit comments

Comments
 (0)