Skip to content

[Bug] SpringCloudServiceInstanceNotificationCustomizer causes "Unsupported protocol" error when Spring Cloud and Dubbo services coexist on the same Nacos namespace #16108

@onceMisery

Description

@onceMisery

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • 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

  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 "*":

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?

  • 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?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions