kragniz / kragniz/python-etcd3

RpcError when lease has expired is raised unhandled.

Open
#113 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
450
Forks
194
PR merge metrics
No merged PRs in 30d

Description

Hi,

While testing how a lease works i noticed that upon a lease expiration this unhandled exception is raised:

**grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.NOT_FOUND, etcdserver: requested lease not found)>**

I used the python debugger and the error handling seems to fail in the _handle_errors decorator [here](https://github.com/kragniz/python-etcd3/blob/master/etcd3/client.py#L34)

pdb output:

> except grpc.RpcError as exc:
(Pdb) n
> /usr/lib/python2.7/site-packages/etcd3/client.py(33)handler()
-> code = exc.code()
(Pdb) n
> /usr/lib/python2.7/site-packages/etcd3/client.py(34)handler()
-> exception = _EXCEPTIONS_BY_CODE.get(code)
(Pdb) print code
StatusCode.NOT_FOUND
(Pdb) print _EXCEPTIONS_BY_CODE.get(code)
None
(Pdb) n
> /usr/lib/python2.7/site-packages/etcd3/client.py(35)handler()
-> if exception is None:
(Pdb) n
> /usr/lib/python2.7/site-packages/etcd3/client.py(36)handler()
-> raise

The code i used to test it:

```python
import etcd3
from etcd3 import exceptions
import time

etcd_con = etcd3.client()

lease = etcd_con.lease(ttl=1)

time.sleep(3)

try:
etcd_con.put('/my_key', '1', lease.id)
except exceptions.Etcd3Exception:
pass
```

It is also strange that if the process sleeps for 2 seconds instead of 3 the lease does not expire as expected since the ttl is set to 1 sec.

Best Regards

Contributor guide

Open the contributing guide

Research direction

Read etcd3/client.py at the _handle_errors decorator and the _EXCEPTIONS_BY_CODE mapping, then reproduce the reported lease-expiration example with a one-second TTL. Check the behavior for StatusCode.NOT_FOUND and for the differing sleep durations; done means the expired-lease result is handled consistently and the TTL behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.