summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@samsung.com>2018-12-20 20:35:57 +0300
committerBen Pfaff <blp@ovn.org>2018-12-20 10:10:55 -0800
commitbdc000b2aad5b303bbee5cb848f2ea8937e8c283 (patch)
treedf47c85b6209cf765a56925431f7aa6058959cc3 /python
parent5bb6f38b90640a97ab0eb7e4347546ba25746428 (diff)
downloadopenvswitch-bdc000b2aad5b303bbee5cb848f2ea8937e8c283.tar.gz
python: Catch setsockopt exceptions for TCP stream.
'sock.setsockopt' could throw exceptions. For example, if non-blocking connection failed before the call: Traceback (most recent call last): File "../.././test-ovsdb.py", line 896, in <module> main(sys.argv) File "../.././test-ovsdb.py", line 891, in main func(*args) File "../.././test-ovsdb.py", line 604, in do_idl ovs.stream.Stream.open(r)) File "/root/git_/ovs/python/ovs/stream.py", line 190, in open error, sock = cls._open(suffix, dscp) File "/root/git_/ovs/python/ovs/stream.py", line 744, in _open sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) File "/usr/local/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 54] Connection reset by peer This fixes tests on FreeBSD. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/stream.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/python/ovs/stream.py b/python/ovs/stream.py
index ca0d84425..cdfcc399e 100644
--- a/python/ovs/stream.py
+++ b/python/ovs/stream.py
@@ -741,7 +741,11 @@ class TCPStream(Stream):
error, sock = ovs.socket_util.inet_open_active(socket.SOCK_STREAM,
suffix, 0, dscp)
if not error:
- sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+ try:
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+ except socket.error as e:
+ sock.close()
+ return ovs.socket_util.get_exception_errno(e), None
return error, sock