[Bug] SpringCloudServiceInstanceNotificationCustomizer causes "Unsupported protocol" error when Spring Cloud and Dubbo services coexist on the same Nacos namespace
- Dominant language
- Java
- Stars
- 41.6k
- Forks
- 26.4k
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 4
Description
### 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](https://github.com/apache/dubbo/issues?q=is%3Aissue) 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
```yaml
dubbo:
protocol:
port: yourPort
serialization: fastjson2
consumer:
protocol: dubbo
protocols:
dubbo:
name: dubbo
port: yourPort
serialization: fastjson2
timeout: 30000
```
### Steps
1. Register a Spring Cloud service (non-Dubbo) to Nacos.
2. Register a Dubbo consumer application to the same Nacos namespace.
3. The Dubbo consumer has `@DubboReference` on an interface (e.g., `TestApi`) that shares the same application name as the Spring Cloud service.
4. 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 `"*"`:
```java
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:
```java
// 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](https://www.apache.org/foundation/policies/conduct)
Contributor guide
Research direction
Start with SpringCloudServiceInstanceNotificationCustomizer.customize() and its inner MetadataInfo.getMatchedServiceInfos(), then trace the failure at ServiceDiscoveryRegistryDirectory.java:376. Run the reported minimal reproduction with Spring Cloud and Dubbo services in one Nacos namespace. Done means non-Dubbo instances are skipped without IllegalStateException while actual Dubbo providers remain discoverable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100