Commit 587256bb authored by David Wilson's avatar David Wilson

issue #141: unify connect deadline handling

Now there is a single deadline calculated by the parent.Stream
constructor, and reused for both SSH and sudo.
parent d58b5ad7
...@@ -276,6 +276,10 @@ class Stream(mitogen.core.Stream): ...@@ -276,6 +276,10 @@ class Stream(mitogen.core.Stream):
#: Maximum time to wait for a connection attempt. #: Maximum time to wait for a connection attempt.
connect_timeout = 30.0 connect_timeout = 30.0
#: Derived from :py:attr:`connect_timeout`; absolute floating point
#: UNIX timestamp after which the connection attempt should be abandoned.
connect_deadline = None
#: True to cause context to write verbose /tmp/mitogen.<pid>.log. #: True to cause context to write verbose /tmp/mitogen.<pid>.log.
debug = False debug = False
...@@ -306,6 +310,7 @@ class Stream(mitogen.core.Stream): ...@@ -306,6 +310,7 @@ class Stream(mitogen.core.Stream):
self.remote_name = remote_name self.remote_name = remote_name
self.debug = debug self.debug = debug
self.profiling = profiling self.profiling = profiling
self.connect_deadline = time.time() + self.connect_timeout
def on_shutdown(self, broker): def on_shutdown(self, broker):
"""Request the slave gracefully shut itself down.""" """Request the slave gracefully shut itself down."""
......
...@@ -112,8 +112,12 @@ class Stream(mitogen.parent.Stream): ...@@ -112,8 +112,12 @@ class Stream(mitogen.parent.Stream):
def _connect_bootstrap(self): def _connect_bootstrap(self):
password_sent = False password_sent = False
for buf in mitogen.parent.iter_read(self.receive_side.fd, it = mitogen.parent.iter_read(
time.time() + 10.0): fd=self.receive_side.fd,
deadline=self.connect_deadline
)
for buf in it:
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
if buf.endswith('EC0\n'): if buf.endswith('EC0\n'):
self._ec0_received() self._ec0_received()
......
...@@ -149,8 +149,13 @@ class Stream(mitogen.parent.Stream): ...@@ -149,8 +149,13 @@ class Stream(mitogen.parent.Stream):
def _connect_bootstrap(self): def _connect_bootstrap(self):
password_sent = False password_sent = False
for buf in mitogen.parent.iter_read(self.receive_side.fd, it = mitogen.parent.iter_read(
time.time() + 10.0): fd=self.receive_side.fd,
deadline=self.connect_deadline,
display_on_failure=0
)
for buf in it:
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
if buf.endswith('EC0\n'): if buf.endswith('EC0\n'):
self._ec0_received() self._ec0_received()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment