diff options
author | Ilya Maximets <i.maximets@samsung.com> | 2019-01-09 20:30:16 +0300 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2019-01-10 15:39:48 -0800 |
commit | 77f42ca53581089a15ede670f0be6b6203360491 (patch) | |
tree | ddba6bb6ed2f52751d44e021c6e552dbfee6bf75 /python | |
parent | 747652d23e4261f5e526851c958dbec9c8f19a7e (diff) | |
download | openvswitch-77f42ca53581089a15ede670f0be6b6203360491.tar.gz |
stream: Allow timeout configuration for open_block.
On some systems in case where remote is not responding, socket could
remain in SYN_SENT state for a really long time without errors waiting
for connection. This leads to situations where open_blok() hangs for
a few minutes waiting for connection to the DOWN remote.
For example, our "multiple remotes" idl tests hangs waiting for
connection to the WRONG_PORT on FreeBSD in CirrusCI environment.
This leads to test failures because Alarm signal arrives much faster
than ETIMEDOUT from the socket.
This patch allowes to specify timeout value for 'open_block' function.
If the connection takes more time, socket will be closed with
ETIMEDOUT error code. Negative value or None in python could be
used to wait infinitely.
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.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/python/ovs/stream.py b/python/ovs/stream.py index cdfcc399e..da683afd8 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -206,10 +206,12 @@ class Stream(object): raise NotImplementedError("This method must be overrided by subclass") @staticmethod - def open_block(error_stream): + def open_block(error_stream, timeout=None): """Blocks until a Stream completes its connection attempt, either - succeeding or failing. (error, stream) should be the tuple returned by - Stream.open(). Returns a tuple of the same form. + succeeding or failing, but no more than 'timeout' milliseconds. + (error, stream) should be the tuple returned by Stream.open(). + Negative value of 'timeout' means infinite waiting. + Returns a tuple of the same form. Typical usage: error, stream = Stream.open_block(Stream.open("unix:/tmp/socket"))""" @@ -217,6 +219,9 @@ class Stream(object): # Py3 doesn't support tuple parameter unpacking - PEP 3113 error, stream = error_stream if not error: + deadline = None + if timeout is not None and timeout >= 0: + deadline = ovs.timeval.msec() + timeout while True: error = stream.connect() if sys.platform == 'win32' and error == errno.WSAEWOULDBLOCK: @@ -225,10 +230,15 @@ class Stream(object): error = errno.EAGAIN if error != errno.EAGAIN: break + if deadline is not None and ovs.timeval.msec() > deadline: + error = errno.ETIMEDOUT + break stream.run() poller = ovs.poller.Poller() stream.run_wait(poller) stream.connect_wait(poller) + if deadline is not None: + poller.timer_wait_until(deadline) poller.block() if stream.socket is not None: assert error != errno.EINPROGRESS |