Bound all external process calls with a timeout and forced termination

Open
#255 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java

Research direction

Start with UtilsLinuxOs.getWholeDisks, which already uses the CompletableFuture drain, waitFor(timeout) and destroyForcibly pattern, and compare it with the unbounded calls in UtilsLinuxOs.getPartitionFromFilePath, UtilsMacOs and UtilOs.runPowerShellOneLiner. Before writing code, settle where the shared runCommand helper should live, since the issue leaves that open. Done means every ProcessBuilder call site is bounded and force-destroyed on timeout, returns null or an empty list, and logs a warning.

Written by the indexing model from the issue text.

Description

enhancement linux macos windows

Background

PR #254 (#252) added proper timeouts to the USB VID/PID lookups on Windows
(UtilsWinOs.getUsbIds, 15 s) and macOS (UtilsMacOs.runCommandLines, 10 s):
output is drained asynchronously, waitFor(timeout) is honoured, and the child
is destroyForcibly()'d on expiry. Review feedback (Copilot) flagged that the
remaining process calls do not follow this pattern.

Problem

Many ProcessBuilder call sites either:

  • call process.waitFor() with no timeout, or
  • read stdout to EOF with readLine() before calling waitFor(n, SECONDS),
    making the timeout ineffective, and never destroy the child.

A hung child (stale network mount for df, stalled DiskArbitration for
diskutil, slow/broken WMI for PowerShell) can block drive detection,
benchmark setup, or the UI indefinitely.

Affected call sites (non-exhaustive)

  • UtilsLinuxOs.getPartitionFromFilePath (df -k), waitFor() without a timeout
  • UtilsLinuxOs.getDeviceNamesFromPartition (lsblk -no pkname), waitFor() without a timeout
  • UtilsMacOs: df -k, diskutil info (lines ~92, ~153), system_profiler,
    the generic command runner (~208), mount (~318)
  • UtilOs: remaining waitFor() calls with no timeout (Linux SMART/lsblk/udevadm helpers) and
    read-then-waitFor(n) PowerShell helpers (e.g. runPowerShellOneLiner)

Proposed approach

  • Use the existing pattern from UtilsLinuxOs.getWholeDisks:
    CompletableFuture output drain → waitFor(timeout) → destroyForcibly() in finally.
  • Consider one shared helper (e.g. runCommand(timeout, String... cmd) → List<String>)
    so call sites stay consistent. Confirm package/location before adding.
  • Timeouts: 10 s for native tools, 15 s for PowerShell (start-up + WMI).
  • On timeout: log at WARNING and return the existing "unavailable" value
    (null/empty list) so detection failures never block a benchmark.

Priority

Low–medium. Hangs are rare on Linux (sysfs/statfs), more plausible on macOS
(diskutil) and Windows (PowerShell/WMI).

Dominant language
Java
Stars
6
Forks
6
Avg merge
10h 11m
Merged PRs (30d)
12

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 JDiskMark/jdm-java

All issues in JDiskMark/jdm-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.