Unexpect error 'Pulsar error: ServiceUnitNotReady' when try to connect to pulsar

516 Views Asked by At

Hello I was debuging a pulsar code, and I was working perfectly, but one time after a re-execution of the code suddenly show a error, of when try to connect:

Loading .env environment variables...
0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 INFO  [0000-00-00 00:00:00.000 ERROR [0000-00-00 00:00:00.000 ERROR [Traceback (most recent call last):
  File "/home/user/USB/Services/back-worker/src/app.py", line 11, in <module>
0000-00-00 00:00:00.000 ERROR [0000-00-00 00:00:00.000 ERROR [0000-00-00 00:00:00.000 INFO  [    from services.pulsar import consumer
  File "/home/user/USB/Services/back-worker/src/services/__init__.py", line 3, in <module>
0000-00-00 00:00:00.000 INFO  [    from .pulsar import consumer
  File "/home/user/USB/Services/back-worker/src/services/pulsar/__init__.py", line 21, in <module>
    consumer = pulsar.Client(
  File "/home/user/USB/Services/back-worker/.venv/lib/python3.10/site-packages/pulsar/__init__.py", line 748, in subscribe
    c._consumer = self._client.subscribe(topic, subscription_name, conf)
_pulsar.ServiceUnitNotReady: Pulsar error: ServiceUnitNotReady

How can I solve and reconnect again?

Thanks

2

There are 2 best solutions below

0
On

It often happens when the namespace bundle is being unloaded, or the owner of the topic is changed. The broker logs will show the details of why the service unit is not ready. It looks like this:

Namespace bundle for topic XXX not served by this instance. Please redo the lookup

For the client side, it should redo the topic lookup, instead of exposing the ServiceUnitNotReady to users.

I'm not sure which Python client version you are using. It would be ideal to create a GitHub issue Pulsar repo, so that we can track the issue, and so we can make sure fixed in the next version.

0
On

In addition to Penghui's answer, ServiceUnitNotReady doesn't always represent a temporarily error like namespace bundle ownership change. For example, Pulsar proxy could transfer nearly all errors, like authentication error, into a ServiceUnitNotReady error. And Pulsar broker could also return a ServiceUnitNotReady error when the listener name is wrong, which should not be retried.

Therefore, you must check the client's logs for the actual reason. You'd better check broker's logs as well. Feel free to open an issue in https://github.com/apache/pulsar/issues or https://github.com/apache/pulsar/discussions for further discussion.

BTW, currently the underlying C++ client won't retry for lookup failure, i.e. the operation timeout doesn't work. And I'm working on a fix recently.