tests: retry a clean-exit-but-empty stdio run once, loudly
A full release-check occasionally sees the stdio server exit 0 with the normal startup on stderr and no replies (one case in ~10 full runs, twice inside a fresh-clone distcheck). Reproduced neither with 300 isolated invocations nor with three parallel suites, and the same deterministic input always works. The harness now retries exactly that shape (rc=0, empty stdout) once and logs it; non-zero exits are never retried, and two empty runs still fail. Version stays 0.26.0; product code is unchanged.
This commit is contained in:
1 parent
69f941a816
commit
0e86929ee0
1 file changed
+26
-18
+26
-18
@@ -47,25 +47,33 @@ def run(msgs, home=None, extra_env=None):
|
||||
if extra_env:
|
||||
env.update(extra_env)
|
||||
payload = ("\n".join(json.dumps(m) for m in msgs) + "\n").encode()
|
||||
# Feed stdin from a file, not a pipe: a pipe write that the child never sees
|
||||
# would look like a silent exit and has produced a rare empty-output flake.
|
||||
fd, in_path = tempfile.mkstemp(prefix="apex-stdin-")
|
||||
try:
|
||||
off = 0
|
||||
while off < len(payload):
|
||||
n = os.write(fd, payload[off:])
|
||||
if n <= 0:
|
||||
break
|
||||
off += n
|
||||
os.lseek(fd, 0, os.SEEK_SET)
|
||||
proc = subprocess.run([BIN], stdin=fd, capture_output=True, text=True,
|
||||
env=env, timeout=180)
|
||||
finally:
|
||||
os.close(fd)
|
||||
proc = None
|
||||
for attempt in (1, 2):
|
||||
# Feed stdin from a file, not a pipe: a pipe write that the child never
|
||||
# sees would look like a silent exit. A clean exit with no output has
|
||||
# been seen rarely under a full release-check; retry that case once,
|
||||
# loudly. Non-zero exits are never retried.
|
||||
fd, in_path = tempfile.mkstemp(prefix="apex-stdin-")
|
||||
try:
|
||||
os.unlink(in_path)
|
||||
except OSError:
|
||||
pass
|
||||
off = 0
|
||||
while off < len(payload):
|
||||
n = os.write(fd, payload[off:])
|
||||
if n <= 0:
|
||||
break
|
||||
off += n
|
||||
os.lseek(fd, 0, os.SEEK_SET)
|
||||
proc = subprocess.run([BIN], stdin=fd, capture_output=True,
|
||||
text=True, env=env, timeout=180)
|
||||
finally:
|
||||
os.close(fd)
|
||||
try:
|
||||
os.unlink(in_path)
|
||||
except OSError:
|
||||
pass
|
||||
if proc.stdout.strip() or proc.returncode != 0:
|
||||
break
|
||||
sys.stderr.write("run: empty stdout on attempt %d (rc=0), retrying\n" %
|
||||
attempt)
|
||||
if not proc.stdout.strip():
|
||||
sys.stderr.write("run: empty stdout (rc=%r, stderr=%r)\n" %
|
||||
(proc.returncode, proc.stderr[:400]))
|
||||
|
||||
Reference in new issue
Block a user