Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复注册中心域名解析导致的单点问题,参考:#2545 #4293

Merged
merged 3 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Registry getRegistry(URL url) {
url = url.setPath(RegistryService.class.getName())
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
.removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
String key = url.toServiceString();
String key = url.toServiceStringWithoutResolving();
// Lock the registry access process to ensure a single instance of the registry
LOCK.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.alibaba.dubbo.registry.NotifyListener;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.RegistryFactory;

import junit.framework.Assert;
import org.junit.Test;

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

@Test
public void testRegistryFactoryIpCache() throws Exception {
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233"));
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"));
Assert.assertEquals(registry1, registry2);
String hostName = NetUtils.getLocalAddress().getHostName();
String ip = NetUtils.getLocalAddress().getHostAddress();
Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + hostName + ":2233"));
Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + ip + ":2233"));
if (hostName.equals(ip)) {
Assert.assertEquals(registry1, registry2);
} else {
Assert.assertNotSame(registry1, registry2);
}
}

@Test
Expand Down