pio check hangs forever when the analyser executable is missing

Open Beginner friendly
#5,554 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli, tooling

Research direction

Read platformio/proc.py and inspect exec_command, especially how Popen and the AsyncPipeBase streams are cleaned up when process creation raises FileNotFoundError. Reproduce with the missing clang-tidy executable using the provided platformio.ini. Done means pio check reports the error and exits with a non-zero status instead of hanging.

Written by the indexing model from the issue text.

Description

  • PlatformIO Core.
Configuration

Operating system: Linux x86-64 (Fedora), Python 3.14

PlatformIO Version (platformio --version): PlatformIO Core, version 6.2.0

Description of problem

pio check never exits when the analyser's executable is missing. It prints the
FileNotFoundError traceback and the "An unexpected error occurred" banner, and
then the process hangs until it is killed. In CI this turns a broken tool package
into a job that runs until its timeout.

Steps to Reproduce
  1. Create a project with src/main.cpp containing int main() { return 0; } and the
    platformio.ini below.
  2. Run pio check once, so tool-clangtidy gets installed.
  3. Delete ~/.platformio/packages/tool-clangtidy/clang-tidy.
  4. Run pio check again.
Actual Results
Checking repro > clangtidy (platform: native)
FileNotFoundError: Traceback (most recent call last):
  File ".../platformio/check/cli.py", line 156, in cli
  File ".../platformio/check/tools/base.py", line 239, in check
  File ".../platformio/check/tools/base.py", line 192, in execute_check_cmd
  File ".../platformio/proc.py", line 114, in exec_command
  File ".../subprocess.py", line 1039, in __init__
  ...
FileNotFoundError: [Errno 2] No such file or directory: '~/.platformio/packages/tool-clangtidy/clang-tidy'

============================================================

An unexpected error occurred. Further steps:
...
============================================================

and the process does not exit (timeout 60 pio check ends with exit code 124).

Expected Results

pio check reports the error and exits with a non-zero status.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:repro]
platform = native
check_tool = clangtidy

Source file to reproduce issue:

int main() { return 0; }
Additional info

execute_check_cmd() passes two proc.LineBufferedAsyncPipe objects to
proc.exec_command(). Each one starts a non-daemon reader thread in its
constructor (AsyncPipeBase.__init__). In exec_command() the pipes are closed in
a finally that sits inside with subprocess.Popen(...), so when Popen itself
raises (here FileNotFoundError), the finally never runs, the reader threads stay
blocked on their pipes, and the interpreter waits for them forever at exit.

Moving the try/finally outside the with fixes it; with this change the same
reproduction exits with status 1:

    try:
        with subprocess.Popen(*args, **kwargs) as p:
            result["out"], result["err"] = p.communicate()
            result["returncode"] = p.returncode
    except KeyboardInterrupt as exc:
        raise exception.AbortedByUser() from exc
    finally:
        for s in ("stdout", "stderr"):
            if isinstance(kwargs[s], AsyncPipeBase):
                kwargs[s].close()  # pylint: disable=no-member

The same code is in develop (platformio/proc.py, exec_command).

Dominant language
Python
Stars
9.6k
Forks
916
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from platformio/platformio-core

All issues in platformio/platformio-core

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.