infiniflow/ragflow · warning · RuntimeError

Process finished but returncode is None

Error message

Process finished but returncode is None

What it means

Defensive check inside the shared `async_run_command` helper: after `proc.communicate()` resolves, the transport reports no exit code. In CPython's asyncio this is effectively unreachable for subprocesses (communicate sets returncode), so hitting it indicates a broken event loop, a patched/edge-case transport, or a library bug rather than a normal failure mode.

Source

Thrown at agent/sandbox/executor_manager/utils/common.py:27

#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
import asyncio
from typing import Tuple


async def async_run_command(*args, timeout: float = 5) -> Tuple[int, str, str]:
    """Safe asynchronous command execution tool"""
    proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)

    try:
        stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
        if proc.returncode is None:
            raise RuntimeError("Process finished but returncode is None")
        return proc.returncode, stdout.decode(), stderr.decode()
    except asyncio.TimeoutError:
        proc.kill()
        await proc.wait()
        raise RuntimeError("Command timed out")
    except Exception as e:
        proc.kill()
        await proc.wait()
        raise e

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Reproduce outside your harness: if it only occurs in tests, fix the mock so communicate() sets a returncode.
  2. Audit for tasks cancelled during loop shutdown; ensure daemon-style subprocess tasks are awaited before loop.close().
  3. If persistent, replace the check by calling `await proc.wait()` once before reading returncode to force reaping.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    rc, out, err = await async_run_command(*cmd, timeout=t)
except RuntimeError as e:
    if "returncode is None" in str(e):
        logger.warning("Subprocess transport anomaly for %s; retrying once", cmd)
        rc, out, err = await async_run_command(*cmd, timeout=t)
    else:
        raise

Prevention

When it happens

Trigger: Calling any helper-wrapped command (docker exec, mkdir, run args) while: the event loop is being closed mid-await, a custom transport or test double returns from communicate() without reaping the process, or exotic interaction with loop shutdown during interpreter exit.

Common situations: Almost never seen in production; occasionally surfaced in test suites that mock create_subprocess_exec, or when tasks are cancelled during loop teardown and the exception path masks the real cancellation error.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/06d280df6a49493c. Report an issue: GitHub.