Skip to content

CmdRun: join pipe reader threads before close returns - #1134

Open
satishnaidu77 wants to merge 1 commit into
HCK-CI:masterfrom
satishnaidu77:cmdrun-join-pipe-threads
Open

satishnaidu77 wants to merge 1 commit into
HCK-CI:masterfrom
satishnaidu77:cmdrun-join-pipe-threads

Conversation

@satishnaidu77

@satishnaidu77 satishnaidu77 commented Sep 9, 2026

Copy link
Copy Markdown

Summary

CmdRun#close waited for the child process with Process.wait2, then returned immediately while stdout/stderr were still being read in background threads. Callers that inspect stddata right after close could see incomplete output.

This showed up in functest host commands (e.g. ping -c 10): the command succeeded and printed PASS:, but validation ran before the last lines were buffered, causing false failures like expected to contain 'PASS:'.

Fix

  • Track stdout/stderr pipe reader threads in @pipe_threads
  • Join those threads in close after wait2 and before returning

Test

Add a spec that runs slow stdout and asserts stddata['stdout'] is complete when close returns (no polling). Existing cmd_run_spec tests check exit status and logging, but do not cover this race.

Test plan

  • bundle exec rspec spec/lib/auxiliary/cmd_run_spec.rb — 8 examples, 0 failures

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly addresses the described race by joining the stdout/stderr reader threads before returning from close, and includes a targeted regression spec to prevent reintroduction.

Pull request overview

This PR fixes a race in AutoHCK::CmdRun#close where the method could return after the child process exited but before the stdout/stderr pipe-reader threads finished buffering output, leading callers to observe incomplete stddata.

Changes:

  • Track stdout/stderr pipe reader threads in @pipe_threads.
  • Join pipe reader threads in #close after Process.wait2 and before returning.
  • Add an RSpec example that verifies stdout is complete immediately after close returns (no polling).
File summaries
File Description
lib/auxiliary/cmd_run.rb Tracks pipe reader threads and joins them during close so stddata is fully buffered before returning.
spec/lib/auxiliary/cmd_run_spec.rb Adds a regression test for the stdout-buffering race by producing slow, line-by-line output and asserting completeness after close.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kostyanf14

Copy link
Copy Markdown
Contributor

ok to test

@kostyanf14

Copy link
Copy Markdown
Contributor

rerun tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants