This article has been included github.com/lkxiaolou/l… Welcome to star.

Those of you who don’t want to read the words can go straight to the bottom and see the mind map

Problem analysis

Many Dubbo users have encountered the following error:

No provider available for the service org.newboo.basic.api.MyDemoService from registry 127.0.0.1:2181 on the consumer 127.0.0.1 using the dubbo version 2.7.6. Please check if the providers have been started and registered.

From the source code this error is located

org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#checkInvokers

protected void checkInvokers(List<Invoker<T>> invokers, Invocation invocation) {
    if (CollectionUtils.isEmpty(invokers)) {
        throw new RpcException(RpcException.NO_INVOKER_AVAILABLE_AFTER_FILTER, "Failed to invoke the method "
                + invocation.getMethodName() + " in the service " + getInterface().getName()
                + ". No provider available for the service " + getDirectory().getConsumerUrl().getServiceKey()
                + " from registry " + getDirectory().getUrl().getAddress()
                + " on the consumer " + NetUtils.getLocalHost()
                + " using the dubbo version " + Version.getVersion()
                + ". Please check if the providers have been started and registered."); }}Copy the code

The code that calls reference when it is configured to check=false is located

org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker#doInvoke

(True verifies at startup)

You can see from the code that the immediate cause of this error is that invokers is empty

Here invoker corresponds to a Provider URL. When no provider is available, invokers is empty

Thinking of the February

This problem seems to be simple, but the actual situation is extremely complicated, and it is impossible to start after encountering it. This paper provides a feasible way of troubleshooting.

The check is divided into two lines: the provider end and the consumer end.

The provider side

Check the provider at the first time, because there are few cases of the provider, you can simply rule out some cases.

A provider can fail in only one case: it is not registered with the registry

Therefore, check whether the provider is registered successfully.

  • If you have a Dubbo console or registry query page, just look it up
  • If there is no visual interface, for example, ZK and ETCD can be connected to the corresponding client to check whether the registration is successful

Using the ZK as an example, you can use ls /dubbo/${service}/providers to view the registered provider

If the provider is not registered successfully, you need to check the possible causes:

  • If the provider fails to start, start it
  • The provider fails to be registered although it is started. View error logs to troubleshoot the fault
  • Is the registry address incorrectly written? Is the environment consistent?

If the provider is registered, the provider is ok. Then look at Consumer.

The consumer end

The check on the consumer side needs to be further subdivided by whether to subscribe (pull) to the corresponding provider information

How do I view consumer subscription information

The consumer subscription information can be viewed from the cache file, which is generated by default as follows:

String defaultFilename = System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + ".cache";
Copy the code

Such as:

~ /. Dubbo/dubbo - registry - ddog - my - demo - c0-127.0.0.1-2181. The cache

With multiple registries, there will be multiple cache files with the following contents:

#Dubbo Registry Cache #Wed Aug 11 20:26:15 CST 2021 Org. Newboo. Basic. API. MyDemoService = empty \ : / / 127.0.0.1 / org newboo. Basic. API. MyDemoService? Application \ = ddog - my - demo - c0 & category \ = routers&check \ = false&dubbo \ = 2.0.2 & init \ = false&interface \ = org newboo. Basic. API. MyD EmoService&loadbalance \ = xxx&methods \ = call&owner \ = roshilikang&pid \ = 3084 & qos enable \ = true&qos port \ = 33333 & release \ = 2.7.6 & s Ide \ = consumer&sticky \ = false&timestamp empty \ \ = 1628684774590: / / 127.0.0.1 / org newboo. Basic. API. MyDemoService? Application \ = ddog - my - demo - c0 & category \ = configurators&check \ = false&dubbo \ = 2.0.2 & init \ = false&interface \ = org newboo. Basic. A pi.MyDemoService&loadbalance\=xxx&methods\=call&owner\=roshilikang&pid\=3084&qos.enable\=true&qos.port\=33333&release\=2 7.6 & side \ = consumer&sticky \ = false&timestamp dubbo \ \ = 1628684774590: / / 127.0.0.1 \ : 20880 / org. Newboo. Basic. API. MyDemoService? Anyhost \ = true&application \ = ddog - my - demo - p0 & deprecated \ = false&dubbo \ = 2.0.2 & dynamic \ = true&generic \ = false&interface \ = org ne Wboo. Basic. API. MyDemoService&methods \ = call&owner \ = roshilikang&pid \ = 2058 & release \ = 2.7.6 & side \ = provider&threads \ = 500 & times tamp\=1628684412247Copy the code

Search for the provider of the corresponding service in the file

Failed to subscribe

If no information is found (the corresponding provider cannot be found), it indicates that the subscription is abnormal. Check whether the consumer log has an error, and whether the registry address and environment configuration are abnormal.

Successful subscription

This file, for example, exists

Dubbo \ : / / 127.0.0.1 \ : 20880 / org. Newboo. Basic. API. MyDemoService? Anyhost \ = true&application \ = ddog - my - demo - p0 & deprecated \ = false&dubbo \ = 2.0.2 & dynamic \ = true&generic \ = false&interface \ = org ne Wboo. Basic. API. MyDemoService&methods \ = call&owner \ = roshilikang&pid \ = 2058 & release \ = 2.7.6 & side \ = provider&threads \ = 500 & times tamp\=1628684412247

The consumer has obtained the provider information

When the consumer gets the provider, it is not guaranteed that the call will not report No Provider. There are several cases that need to be checked

  • Check whether the group and version of the consumer match exactly with the Provider. If they do not match, No Provider is reported
  • Disabled: searches for the override URL corresponding to the service in the cache file, and disabled=true
  • Whether the consumer is configured with routing rules, such as tag routes and conditional routes. Routing rules may cause No Provider

If version or group is specified for consumer (group=read, version=1.0), this error message is displayed:

No provider available from registry 127.0.0.1:2181 for service read/org newboo. Basic. API. MyDemoService: 1.0 on consumer 127.0.0.1 use dubbo version 2.7.6

The group before service is separated by a slash. The version after service is separated by a colon.

This covers 95% of the scenarios, with a rarer one where the consumer fails to generate invokers and the invokers are empty.

In this case, check the error log carefully. If an unknown error occurs, pay attention to it. Here are some of the cases I’ve encountered

  1. In Dubbo 2.6.x, transport implemented netty and Netty4, while in 2.6.10, the netty Transport extension name was changed to netty3; If the provider uses Dubbo 2.6.10 and transport is specified as netty3, the invoker generation fails in the earlier version of dubbo because netty3 extension is not implemented. The consumer appears to have obtained the URL of the provider, but will also report No Provider
  2. Similar to 1, when you customize some extensions to be used only by the provider, some parameters of the provider will be passed to the consumer so that the consumer can use the same extension, but the consumer may not implement the extension, causing the invoker generation failure. Such as custom Dispatcher extensions.

Note: You may ask why provider parameters are passed to consumer? Does that make sense? For example, if the provider specifies json as the serialization protocol, does the consumer also transfer data according to the provider’s serialization protocol JSON? There is no foolproof design

conclusion

Like many troubleshooting methods, narrow the scope of the troubleshooting step by step based on the existing symptoms and finally locate the root cause. Sum it up with a mind map:


Search attention wechat public number “bug catching master”, back-end technology sharing, architecture design, performance optimization, source code reading, problem solving, practice.