Code Monkey home page Code Monkey logo

Comments (3)

MaciekPytel avatar MaciekPytel commented on July 24, 2024

I have the same issue. I think it's quite a serious problem, as it makes a watch with specified timeout pretty much useless (and I'd think it's a common use-case).

Basically the problem is as follows: by default urrlib3 retries 3 times on timeout. So when we specify the timeout of x seconds, what really happens is:

  1. 4 requests with the specified timeout are run. (total time: ~4x seconds)
  2. Once they all timeout MaxRetryError is raised by urllib3.
  3. This triggers retries on different servers
  4. Finally the call fails with EtcdException('No more machines in the cluster'), after much longer than specified in timeout.

I believe the fix would be to disable urllib3 retry when timeout is specified. However, if we do that we run into a different problem: if a pariticular etcd host goes down we won't retry on different servers (as the error we get won't be MaxRetryError).
I think the right thing to do would be to catch ConnectionError in addition to MaxRetryError and apply the same try-other-servers logic. Unfortunately ConnectionError was only introduced in urllib3 1.8.0, while python-etcd requires a version >= 1.7.1.

Would this be a good enough reason to bump the urllib3 version up? Alternatively I can write some more complex error handling that would basically have to catch all urllib3 errors, figure out what happen and re-raise if appropriate (it's a bit ugly, but I can't think of anything else that would work with all existing versions of urllib3 since 1.7.1).

Either way I'm happy to submit a pull request.

from python-etcd.

lavagetto avatar lavagetto commented on July 24, 2024

I think this is part of a larger issue, which is supporting correctly timeouts both client-side and server-side. I don't have that much time to spend on this at the moment, but I'll try to organize some work on properly supporting etcd 2.0.

@MarciekPytel any pull request is welcome.

from python-etcd.

CyberDem0n avatar CyberDem0n commented on July 24, 2024
>>> import etcd
>>> c = etcd.Client()
>>> c.read("/foobar", wait=True, timeout=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/etcd/client.py", line 482, in read
    return self._result_from_response(response)
  File "/usr/local/lib/python2.7/dist-packages/etcd/client.py", line 700, in _result_from_response
    'Unable to decode server response: %s' % e)
etcd.EtcdException: Unable to decode server response: HTTPConnectionPool(host='127.0.0.1', port=4001): Read timed out.

But documentation tells that urllib3.exceptions.TimeoutError should be thrown.

The reason why this happens is:
https://github.com/jplana/python-etcd/blob/master/src/etcd/client.py#L692
response.data property will throw the right exception on which would be catch later on https://github.com/jplana/python-etcd/blob/master/src/etcd/client.py#L698

from python-etcd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.