Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching socket.error raises ValueError #7

Open
GoogleCodeExporter opened this issue Jul 24, 2015 · 2 comments
Open

Catching socket.error raises ValueError #7

GoogleCodeExporter opened this issue Jul 24, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

1. Invoke any method that revolves around sending/receiving data through a 
socket (`send_message`, `read_message`, `send_action`, etc.) in ami.py
2. Wait for or force a failure in the connection that will result in a 
socket.error exception being raised. Every time, a line like this will try to 
catch it:

    ...
    except socket.error as (errno, message):

3. If either errno or message is `None` that line will raise a `ValueError` and 
the exception will not be handled, sometimes failing to close the connection 
(for instance, line 1111 and 1112 in `read_message` of ami.py)


What is the expected output? What do you see instead?

socket.error exception should raise a new `ManagerSocketError` that would allow 
the client to reconnect or shutdown gracefully. Instead, `ValueError` is 
raised, the connection is not closed and `is_connected`  still returns `True`.

What version of the product are you using? On what operating system?

pystrix trunk on Ubuntu 13.10 (python 2.7)

Please provide any additional information 
below.

A simple change to the way socket.error is caught should suffice:

      except socket.error as e:
                    self._close()
                    raise ManagerSocketError("Connection to Asterisk manager broken while reading data: [{errno}] {error}"
            .format(errno=e.errno, error=e.strerror))


Original issue reported on code.google.com by nfantone on 10 Jan 2014 at 2:18

@GoogleCodeExporter
Copy link
Author

Thanks for reporting this, nfantone; I'll need to make some changes to other 
projects where I forgot that socket.error could omit errno, too. There are also 
three other places in pystrix where this is a relevant change.

As much as I love namedtuples and am starting to appreciate .format(), the 
solution you proposed isn't backwards-compatible (and it would generate an ugly 
[None] in the explanation-text), so I'm using a slightly less-efficient 
approach in my fix.

The patch should be committed to version-control by the time you see this, and 
pystrix is scheduled to get some of my time in February to keep pushing its 
documentation and Asterisk-bindings towards the 1.10 and 1.11 releases I've 
mentioned before.

Original comment by red.hamsterx on 10 Jan 2014 at 5:19

  • Changed state: Started
  • Added labels: Priority-Critical
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

You are welcome. Glad to give something back.

Original comment by nfantone on 13 Jan 2014 at 6:56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant