- [ ] I have searched the 
[issues](https://github.com/apache/incubator-dubbo/issues) of this repository 
and believe that this is not a duplicate.
- [ ] I have checked the 
[FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this 
repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.7.1
* Operating System version: Windows 10
* Java version: 8

### Steps to reproduce this issue

1. use multicast registry
2. run provider
3. run consumer

Pls. provide [GitHub address] to reproduce this issue.

### invoke success

What do you expected from the above steps?

### Failed to check the status of the service

What actually happens?
see the code 
below(org.apache.dubbo.registry.multicast.MulticastRegistry#receive):
```
private void receive(String msg, InetSocketAddress remoteAddress) {
        if (logger.isInfoEnabled()) {
            logger.info("Receive multicast message: " + msg + " from " + 
remoteAddress);
        }
        if (msg.startsWith(Constants.REGISTER)) {
            URL url = 
URL.valueOf(msg.substring(Constants.REGISTER.length()).trim());
            registered(url);
        } else if (msg.startsWith(Constants.UNREGISTER)) {
            URL url = 
URL.valueOf(msg.substring(Constants.UNREGISTER.length()).trim());
            unregistered(url);
        } else if (msg.startsWith(Constants.SUBSCRIBE)) {
            URL url = 
URL.valueOf(msg.substring(Constants.SUBSCRIBE.length()).trim());
            Set<URL> urls = getRegistered();
            if (CollectionUtils.isNotEmpty(urls)) {
                for (URL u : urls) {
                    if (UrlUtils.isMatch(url, u)) {
                        String host = remoteAddress != null && 
remoteAddress.getAddress() != null ? 
remoteAddress.getAddress().getHostAddress() : url.getIp();
                        if (url.getParameter("unicast", true) // Whether the 
consumer's machine has only one process
                                && !NetUtils.getLocalHost().equals(host)) { // 
Multiple processes in the same machine cannot be unicast with unicast or there 
will be only one process receiving information
                            unicast(Constants.REGISTER + " " + 
u.toFullString(), host);
                        } else {
                            multicast(Constants.REGISTER + " " + 
u.toFullString());
                        }
                    }
                }
            }
        }/* else if (msg.startsWith(UNSUBSCRIBE)) {
        }*/
    }
```
when consumer and provider in the same machine, 

> String host = remoteAddress != null && remoteAddress.getAddress() != null ? 
> remoteAddress.getAddress().getHostAddress() : url.getIp();

the host value maybe 127.0.0.1

> NetUtils.getLocalHost()

maybe the actual ip adress such as 192.168.0.108
then 

> url.getParameter("unicast", true) && !NetUtils.getLocalHost().equals(host)

is true,and 

> unicast(Constants.REGISTER + " " + u.toFullString(), host) 

is called, then only one process has received the information (in my test, it's 
consumer that does not receive the provider's register message), in this case 
when consumer call a rpc method, it will throw an exception

If there is an exception, please attach the exception trace:

```
Exception in thread "main" 
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'demoServiceComponent': Injection of 
@org.apache.dubbo.config.annotation.Reference dependencies is failed; nested 
exception is java.lang.IllegalStateException: Failed to check the status of the 
service org.apache.dubbo.demo.DemoService. No provider available for the 
service org.apache.dubbo.demo.DemoService from the url 
multicast://224.5.6.7:1234/org.apache.dubbo.registry.RegistryService?application=dubbo-demo-annotation-consumer&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=17400&register.ip=192.168.0.108&side=consumer&timestamp=1548861796846
 to the consumer 192.168.0.108 use dubbo version 
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:133)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at 
org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
        at org.apache.dubbo.demo.consumer.Application.main(Application.java:36)
Caused by: java.lang.IllegalStateException: Failed to check the status of the 
service org.apache.dubbo.demo.DemoService. No provider available for the 
service org.apache.dubbo.demo.DemoService from the url 
multicast://224.5.6.7:1234/org.apache.dubbo.registry.RegistryService?application=dubbo-demo-annotation-consumer&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=17400&register.ip=192.168.0.108&side=consumer&timestamp=1548861796846
 to the consumer 192.168.0.108 use dubbo version 
        at 
org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:398)
        at 
org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:306)
        at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:230)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:162)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:146)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:140)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:122)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:116)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:49)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:342)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:522)
        at 
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
        at 
org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:129)
        ... 12 more
Disconnected from the target VM, address: '127.0.0.1:59047', transport: 'socket'
```


[ Full content available at: 
https://github.com/apache/incubator-dubbo/issues/3401 ]
This message was relayed via gitbox.apache.org for 
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to