[Bug] SpringCloudServiceInstanceNotificationCustomizer causes "Unsupported protocol" error when Spring Cloud and Dubbo services coexist on the same Nacos namespace
Pre-check
- [x] I am sure that all the content I provide is in English.
Search before asking
- [x] I had searched in the issues and found no similar issues.
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
Dubbo version 3.2.x , openJdk 17 , Ubuntu20.04
Steps to reproduce this issue
Environment
- Dubbo version: 3.2.x (tested on 3.2.18 / 3.2.19)
- Registry: Nacos
- Spring Cloud and Dubbo services registered under the same Nacos namespace
Configuration
dubbo:
protocol:
port: yourPort
serialization: fastjson2
consumer:
protocol: dubbo
protocols:
dubbo:
name: dubbo
port: yourPort
serialization: fastjson2
timeout: 30000
Steps
- Register a Spring Cloud service (non-Dubbo) to Nacos.
- Register a Dubbo consumer application to the same Nacos namespace.
- The Dubbo consumer has
@DubboReferenceon an interface (e.g.,TestApi) that shares the same application name as the Spring Cloud service. - Start the Dubbo consumer application.
Error logs
[DUBBO] Failed to refer invoker for interface: interface com.example.TestApi,
url:(DefaultServiceInstance{serviceName='example-service', host='172.23.45.123', port=11105,
enabled=true, healthy=true, metadata={preserved.register.source=SPRING_CLOUD}},
service{name='com.example.TestApi', group='null', version='null', protocol='rest',
port='TestApiServiceRestPort', params={},})
service is: interface com.example.TestApi, only support [jax-rs, spring-webmvc] annotation,
dubbo version: 3.2.19, error code: 4-3.
[DUBBO] Unsupported protocol., dubbo version: 3.2.19, error code: 4-1.
java.lang.IllegalStateException: Cannot create invokers from url address list (total 1)
at o.a.d.registry.client.ServiceDiscoveryRegistryDirectory.refreshInvoker(ServiceDiscoveryRegistryDirectory.java:376)
What you expected to happen
When a Dubbo consumer discovers Spring Cloud instances (which have no Dubbo metadata), it should gracefully skip those instances instead of throwing IllegalStateException. The consumer should wait for actual Dubbo provider instances to register.
Anything else
Root cause analysis
The issue involves two primary components working together incorrectly:
1. SpringCloudServiceInstanceNotificationCustomizer.customize() sets REST protocol metadata on Spring Cloud instances with a wildcard path "*":
MetadataInfo.ServiceInfo serviceInfo = new MetadataInfo.ServiceInfo(
"*", "*", "*", REST_PROTOCOL, instance.getPort(), "*", new HashMap<>());
2. SpringCloudServiceInstanceNotificationCustomizer inner MetadataInfo.getMatchedServiceInfos() only filters out non-REST consumers when consumerProtocol != null. When @DubboReference does not explicitly specify protocol, the consumerProtocolServiceKey.getProtocol() is null, bypassing the filter:
// Original code: null protocol falls through to REST matching
if (consumerProtocol != null && !REST_PROTOCOL.equalsIgnoreCase(consumerProtocol)) {
return Collections.emptyList();
}
Do you have a (mini) reproduction demo?
- [x] Yes, I have a minimal reproduction demo to help resolve this issue more effectively!
Are you willing to submit a pull request to fix on your own?
- [x] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
An error occurs at startup, but it does not affect usage. However, it generates a lot of additional alert noise.
@zrlw Thanks for the tag! Could you share what specific aspects we should discuss?
You should set up a separate namespace for your Dubbo; Nacos is only responsible for discovery and scheduling.
You should set up a separate namespace for your Dubbo; Nacos is only responsible for discovery and scheduling.
Thanks for your reply ! I’ve always used it this way before. But since I joined this company, you know how it is—there are just so many things you can’t control.
btw: I also believe a good product should be simpler to use. @YuanJie2001