lowRISC / lowRISC/dvsim

Bug in run_cmd_with_timeout means you always get an error about `ls -d` timing out

Open Beginner friendly
#225 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
13
Forks
21
Avg merge
1d 11h
Merged PRs (30d)
8

Description

If the `SCRATCH_ROOT` env var is set you hit this code: https://github.com/lowRISC/dvsim/blob/0f1346640562da32bc399530b309487e9e1df832/src/dvsim/cli/run.py#L62-L72

That calls this function: https://github.com/lowRISC/dvsim/blob/0f1346640562da32bc399530b309487e9e1df832/src/dvsim/utils/subprocess.py#L28-L39

(With the wrong type for `exit_on_failure` btw, but who needs correct types?)

The problem is that function will basically *always* say that the command has timed out. The bug is due to the classic truthiness footgun that Python shares with Javascript. Unlike in Typescript where you can (with considerable effort) set up ESLint to ban truthiness bugs, I'm not aware of a way to do that in Python so you just have to be vigilant.

Here is the bug (and the other `poll` further down): https://github.com/lowRISC/dvsim/blob/0f1346640562da32bc399530b309487e9e1df832/src/dvsim/utils/subprocess.py#L53-L54

It needs to be `if p.poll() is not None:`.

`poll()` returns the exit code or `None` if the process has not exited. If the command succeeds then `p.poll()` returns 0, and `if 0:` will never succeed so it thinks the command times out.

Contributor guide

Open the contributing guide

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.

Research direction

Start with src/dvsim/cli/run.py and the run_cmd_with_timeout implementation in src/dvsim/utils/subprocess.py, following the SCRATCH_ROOT path and the referenced poll checks. Verify the behavior with the `ls -d` command and confirm that a successful exit is no longer reported as a timeout.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.