OSError [Errno 24] After 338 asyncio wait_for Timeouts A developer testing an agent's shell tool found that 338 earlier asyncio.wait_for timeouts on proc.communicate() left child processes and their pipes alive, eventually crashing with OSError [Errno 24] Too many open files. Adding proc.kill() and await proc.wait() in the TimeoutError branch let 300 timed-out calls under a 256-descriptor limit finish with 7 open descriptors and 0 live children instead of failing at call 83. Each leaked call held two pipe ends and one pidfd, roughly three descriptors, and gc.collect() did not reclaim them. In my test, an agent's shell tool died with OSError: Errno 24 Too many open files , raised from File "/usr/lib/python3.14/subprocess.py", line 1886, in execute child , and the real cause was 338 earlier calls to asyncio.wait for proc.communicate , timeout that timed out and left their child processes running. The fix is two lines in the except TimeoutError branch, proc.kill then await proc.wait , and with them 300 timed-out calls under a 256-descriptor limit ended with 7 open descriptors and 0 live children instead of a crash at call 83. This story was written with the assistance of an AI writing program. Every number below comes from CPython 3.14.4 on Linux, and the main scripts ran twice with the same counts. This is the tool runner I use now: python import asyncio async def run tool cmd, timeout=30.0 : proc = await asyncio.create subprocess exec cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE try: async with asyncio.timeout timeout : out, err = await proc.communicate except TimeoutError: proc.kill the child does not die on its own await proc.wait reap it; this closes the pipes and the pidfd raise return proc.returncode, out, err The rest of this post shows what the short version leaks, and why it takes hundreds of calls before anything breaks. This is what the shell tool looked like before: proc = await asyncio.create subprocess exec cmd, stdout=PIPE, stderr=PIPE try: out, err = await asyncio.wait for proc.communicate , timeout except TimeoutError: return "tool timed out" The timeout works in the sense that the caller gets control back on time. What it does not do is touch the child. wait for cancels the communicate coroutine, and cancelling a coroutine that reads pipes stops the reading. The process on the other end keeps running, and the event loop keeps its pipes open so it can still report the exit code later. This is the same family of bug as my earlier posts on subprocess.run orphans and ThreadPoolExecutor threads: the caller stops waiting and assumes the work stopped too. The fake tool is sleep 30 with stdout and stderr piped, called with a 0.05 s timeout in a loop. After each run the script counts entries in /proc/self/fd and checks /proc/