Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/machine: Read stderr from ssh-keygen correctly #23585

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

ashley-cui
Copy link
Member

@ashley-cui ashley-cui commented Aug 12, 2024

Read stderr from ssh-keygen before calling wait(), since cmd.Wait() closes cmd.StderrPipe() after it exits.

Found this when hunting for the key generation flake from the uncategorized flakes issue. I'm not sure if this fixes it, since no machine flakes have been triggering for me since last Thursday, but since it's a bug it's worth fixing anyway.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added release-note-none do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 12, 2024
@ashley-cui ashley-cui marked this pull request as ready for review August 12, 2024 15:14
@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 12, 2024
@ashley-cui ashley-cui added No New Tests Allow PR to proceed without adding regression tests and removed machine labels Aug 12, 2024
@rhatdan
Copy link
Member

rhatdan commented Aug 12, 2024

Would something like:

cmd := exec.Command("...")
  stdout := new(bytes.Buffer)
  stderr := new(bytes.Buffer)

  cmd.Stdout = stdout
  cmd.Stderr = stderr

  if err := cmd.Start(); err != nil {
      ...
  }

  if err := cmd.Wait(); err != nil {
      ...
  }

  in := bufio.NewScanner(io.MultiReader(stdout, stderr))
  for in.Scan() {
      fmt.Println(in.Text())
  }

Make more sense?

pkg/machine/keys.go Outdated Show resolved Hide resolved
Read stderr from ssh-keygen before calling wait(), since cmd.Wait() closes cmd.StderrPipe() after it exits, causing a read-on-closed-pipe error.

Signed-off-by: Ashley Cui <[email protected]>
@baude
Copy link
Member

baude commented Aug 12, 2024

LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2024
Copy link
Contributor

openshift-ci bot commented Aug 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashley-cui, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit d4ecd57 into containers:main Aug 13, 2024
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. machine No New Tests Allow PR to proceed without adding regression tests release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants