Skip to content

Commit a2b91d8

Browse files
committed
mitogen/parent: Make the timeout configurable
-SSH command size: 906 +SSH command size: 905 Original Minimized Compressed -mitogen.parent 99063 96.7KiB 51318 50.1KiB 51.8% 12979 12.7KiB 13.1% +mitogen.parent 99212 96.9KiB 51385 50.2KiB 51.8% 12999 12.7KiB 13.1% Signed-off-by: Marc Hartmayer <[email protected]>
1 parent 936b67a commit a2b91d8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mitogen/parent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,9 @@ class Connection(object):
13781378
#: user.
13791379
exception = None
13801380

1381+
#: First stage timeout in seconds.
1382+
_first_stage_timeout = 10
1383+
13811384
#: Extra text appended to :class:`EofError` if that exception is raised on
13821385
#: a failed connection attempt. May be used in subclasses to hint at common
13831386
#: problems with a particular connection method.
@@ -1419,6 +1422,7 @@ def __repr__(self):
14191422
# n: size of the compressed core source to be read
14201423
# V: data chunk
14211424
# rl: list of FDs ready for reading
1425+
# t: timeout value in seconds
14221426
# _: throw away variable
14231427

14241428
# Final os.close(STDOUT_FILENO) to avoid --py-debug build corrupting stream with
@@ -1446,7 +1450,7 @@ def _first_stage():
14461450
C=''.encode()
14471451
V='V'
14481452
while n>len(C) and V:
1449-
rl,_,_=select.select([0],[],[],10)
1453+
rl,_,_=select.select([0],[],[],t)
14501454
if not rl:
14511455
raise Exception("TimeoutError")
14521456
V=os.read(0,n-len(C))
@@ -1496,6 +1500,7 @@ def get_boot_command(self):
14961500
encoded.decode(),
14971501
self.options.remote_name,
14981502
str(len(self.get_preamble())),
1503+
str(self._first_stage_timeout),
14991504
]
15001505

15011506
def get_econtext_config(self):

tests/first_stage_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def test_timeout_error(self):
147147
options = mitogen.parent.Options(max_message_size=123)
148148
conn = mitogen.parent.Connection(options, self.router)
149149
conn.context = mitogen.core.Context(None, 123)
150+
# We do not want to wait the default of 10s, change it to 1s
151+
conn._first_stage_timeout = 1
150152
args = conn.get_boot_command()
151153

152154
# The boot command should write an ECO marker to stdout, read the

0 commit comments

Comments
 (0)