Skip to content

Is it necessary to make refresh_lease one long-lived coroutine? #33

Description

@garvenlee

Here is my code:

    async def refresh_lease(self, lease_id: int, *, period: int):
        refresh = self.aetcd_client.refresh_lease                        
        while True:            
            # stream_stream meth but only request once with request_timeout            
            # so this will raise ConnectionTimeoutError(ClientError),           
            # then it means the service is down in etcd's view, and service supplier            
            # must register itself again            
            reply = await refresh(lease_id)  # let registered key closed with lease itself            
            self.last_refresh_time = monotonic()  # update if succeed            
            logger.debug(f"[EtcdLease] refresh_lease got a reply: {reply.ID} / {self.lease_id}")            
            await sleep(period)

Two hours after the periodic execution of refresh_lease of my code, I got the following exceptions:

Traceback (most recent call last):
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/aetcd/client.py", line 21, in handler
    return await f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/aetcd/client.py", line 42, in handler
    return await f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/aetcd/client.py", line 1033, in refresh_lease
    async for reply in self.leasestub.LeaseKeepAlive(
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/grpc/aio/_call.py", line 356, in _fetch_stream_responses
    await self._raise_for_status()
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/grpc/aio/_call.py", line 263, in _raise_for_status
    raise _create_rpc_error(
grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
	status = StatusCode.INTERNAL
	details = "Internal error from Core"
	debug_error_string = "Failed "execute_batch": (<grpc._cython.cygrpc.SendMessageOperation object at 0x7ff7890dd030>,)"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/chatp-0.0.1-py3.11.egg/chatp/discovery/etcd.py", line 62, in refresh_lease
    reply = await refresh(
            ^^^^^^^^^^^^^^
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/aetcd/client.py", line 23, in handler
    exceptions._handle_exception(e)
  File "/home/garvenlee/anaconda3/envs/py311/lib/python3.11/site-packages/aetcd/exceptions.py", line 80, in _handle_exception
    raise e(error_details) from error
aetcd.exceptions.InternalError: Internal error from Core

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions