nacos-group / nacos-group/nacos-sdk-python

_process_polling_result 队列控制问题

Open
#190 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
471
Forks
155
PR merge metrics
No merged PRs in 30d

Description

当 watch 执行完后,线程仍在后台执行,notify_queue.get() 时读取不到数据导致异常。

客户端代码:

class InstallConfig:
    def __init__(self):
        logger.info("connect to nacos: {}, nameserver: {}, group: {}, dataId: {}",
                    NACOS_SERVER,
                    NACOS_NAMESPACE,
                    NACOS_GROUP,
                    NACOS_DATA_ID)

        self.client = nacos.NacosClient(NACOS_SERVER, namespace=NACOS_NAMESPACE)

        # 添加以下设置未能解决 add_config_watcher 退出时的线程异常
        # Exception in thread Thread-6 (_process_polling_result),
        # self.client.set_options(default_timeout=1)
        # self.client.set_options(pulling_timeout=1)
        # self.client.set_options(pulling_config_size=3)
        self.client.set_options(callback_thread_num=10)

        self.client.add_config_watcher(NACOS_DATA_ID, NACOS_GROUP, self.config_watcher)
        self.config = yaml.safe_load(self.client.get_config(NACOS_DATA_ID, NACOS_GROUP))

    def config_watcher(self, args):
        logger.info("run config watcher: {}", args)
        self.config = yaml.safe_load(args["raw_content"])


if __name__ == "__main__":
    config = InstallConfig()

    for i in range(10):
        print(config.get_minio_config().server)
        time.sleep(1)

watcher 队列异常,watcher 能接受消息,但在 for 之后报如下异常

Exception in thread Thread-14 (_process_polling_result):
Traceback (most recent call last):
  File "/root/anaconda3/envs/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/root/anaconda3/envs/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/root/anaconda3/envs/lib/python3.10/site-packages/nacos/client.py", line 817, in _process_polling_result
    cache_key, content, md5 = self.notify_queue.get()
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/queues.py", line 103, in get
    res = self._recv_bytes()
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/root/anaconda3/envs/lib/python3.10/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in nacos/client.py at _process_polling_result and inspect how notify_queue.get() is handled when add_config_watcher is no longer active. Reproduce the EOFError with the provided InstallConfig example and trace the watcher thread lifecycle. Done means the watcher can stop after the loop without emitting the queue exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.