jplana / python-etcd

A python client for etcd
Other
522 stars 210 forks source link

read() read(wait=True) racecondition #200

Open mb-dbc-dk opened 8 years ago

mb-dbc-dk commented 8 years ago

As I see it, there's no way of "get or wait for" key, in the read call.

you can do:

try:
  return client.read(key)
except EtcdKeyNotFound as e:
  return client.read(key, wait=True, timeout=...)

However I just got hit by, key created between the 2 calls. I did this for a number of keys, that were created in the same order, the 2 scripts got synchronized, and race condition appeared (not very often, only got hit by it once).

lavagetto commented 8 years ago

I'm not sure if we make available the etcd index of the response in the case of a 404 response; we should probably do that so that you can wait on the key from the index you got on your first request.