Skip to content

Commit d2b0b42

Browse files
committed
mitogen: first_stage: Break the while loop in case of EOF
The current implementation can cause an infinite loop, leading to a process that hangs and consumes 100% CPU. This occurs because the EOF condition is not handled properly, resulting in repeated select(...) and read(...) calls. The fix is to properly handle the EOF condition and break out of the loop when it occurs. -SSH command size: 822 +SSH command size: 838 -mitogen.parent 98746 96.4KiB 51215 50.0KiB 51.9% 12922 12.6KiB 13.1% +mitogen.parent 98827 96.5KiB 51219 50.0KiB 51.8% 12942 12.6KiB 13.1% Fixes: #1348 Signed-off-by: Marc Hartmayer <[email protected]>
1 parent ea59e4d commit d2b0b42

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mitogen/parent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ def __repr__(self):
14161416
# r: read side of core_src FD.
14171417
# w: write side of core_src FD.
14181418
# C: the decompressed core source.
1419+
# n: size of the compressed core source to be read
1420+
# V: data chunk
14191421

14201422
# Final os.close(STDOUT_FILENO) to avoid --py-debug build corrupting stream with
14211423
# "[1234 refs]" during exit.
@@ -1437,8 +1439,8 @@ def _first_stage():
14371439
os.environ['ARGV0']=sys.executable
14381440
os.execl(sys.executable,sys.executable+'(mitogen:%s)'%sys.argv[2])
14391441
os.write(1,'MITO000\n'.encode())
1440-
C=''.encode()
1441-
while int(sys.argv[3])-len(C)and select.select([0],[],[]):C+=os.read(0,int(sys.argv[3])-len(C))
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
14421444
C=zlib.decompress(C)
14431445
f=os.fdopen(W,'wb',0)
14441446
f.write(C)

0 commit comments

Comments
 (0)