Skip to content

Terminal output capture is unreliable due to race conditions and fixed timeouts #4

@midhunann

Description

@midhunann

Location

src/environment.ts (approx. lines 87–96)


Problem

The environment detection logic captures terminal output by writing to a temporary file and reading it after a fixed delay. This approach is unreliable and can fail on slower systems or under load.

Current behavior

terminal.sendText(`${checkCommand} ghci > /tmp/ghci_path 2>/dev/null || echo "not found" > /tmp/ghci_path`);

setTimeout(async () => {
    const content = await vscode.workspace.fs.readFile(
        vscode.Uri.file('/tmp/ghci_path')
    );
}, 500);

Issues Identified

Race condition

  • The file may be read before the terminal finishes writing to it
  • Results in false negatives even when tools are installed

Fixed timeout

  • Hard-coded 500ms delay is unreliable
  • Slower machines or busy systems may require more time

Missing error handling

  • No clear handling if the file does not exist
  • Errors are silently ignored, making debugging difficult

Fragile design

  • Depends on terminal behavior and filesystem timing
  • Not suitable for reliable environment detection in a VS Code extension

Expected Behavior

  • Tool detection should be deterministic and reliable
  • No dependency on arbitrary timeouts
  • Proper error handling if a tool is missing
  • Works consistently across different system speeds and platforms

How to Test

  1. Install the extension from the VS Code marketplace (or via VSIX).

  2. Clone this repository, which contains simple Haskell files for testing:

    https://github.com/midhunann/haskell-test
    
  3. Open the repository in VS Code.

  4. Run the extension’s Haskell execution commands.

  5. Verify that:

    • Environment detection is consistent
    • No false “tool not found” errors occur
    • Behavior is stable on slower systems as well

Priority

High — causes intermittent failures and makes environment detection unreliable, especially on slower or heavily loaded systems.

NOTE: Come up with a solution and then start working on this.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions