Skip to content

Commit 50ef8d7

Browse files
committed
mitogen: _first_stage: Add timeout handling
Do not wait/block forever for data to be read. Add a test for this. The test can be run using the following command: PYTHONPATH=$(pwd)/tests:$PYTHONPATH python -m unittest -v tests.first_stage_test -SSH command size: 838 +SSH command size: 894 Original Minimized Compressed -mitogen.parent 98827 96.5KiB 51219 50.0KiB 51.8% 12942 12.6KiB 13.1% +mitogen.parent 99034 96.7KiB 51295 50.1KiB 51.8% 12970 12.7KiB 13.1% Signed-off-by: Marc Hartmayer <[email protected]>
1 parent a17ee01 commit 50ef8d7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mitogen/parent.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,8 @@ def __repr__(self):
14181418
# C: the decompressed core source.
14191419
# n: size of the compressed core source to be read
14201420
# V: data chunk
1421+
# rl: list of FDs ready for reading
1422+
# _: throw away variable
14211423

14221424
# Final os.close(STDOUT_FILENO) to avoid --py-debug build corrupting stream with
14231425
# "[1234 refs]" during exit.
@@ -1439,8 +1441,15 @@ def _first_stage():
14391441
os.environ['ARGV0']=sys.executable
14401442
os.execl(sys.executable,sys.executable+'(mitogen:%s)'%sys.argv[2])
14411443
os.write(1,'MITO000\n'.encode())
1442-
n=int(sys.argv[3]);C=''.encode();V='V'
1443-
while n>len(C) and V:select.select([0],[],[]);V=os.read(0,n-len(C));C+=V
1444+
n=int(sys.argv[3])
1445+
C=''.encode()
1446+
V='V'
1447+
while n>len(C) and V:
1448+
rl,_,_=select.select([0],[],[],10)
1449+
if not rl:
1450+
raise Exception("TimeoutError")
1451+
V=os.read(0,n-len(C))
1452+
C+=V
14441453
C=zlib.decompress(C)
14451454
f=os.fdopen(W,'wb',0)
14461455
f.write(C)

0 commit comments

Comments
 (0)