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

Fixed the run output log files to be populated when debug=true #53

Merged
merged 5 commits into from
Sep 28, 2024

Conversation

ashrithagoramane
Copy link
Collaborator

Issue with the logs being output to file when debug flag is set to true.
When the debug=true the StreamOuput code block only streams the output to STDOUT and fails to populate the stdout and stderr field.

@ashrithagoramane ashrithagoramane marked this pull request as draft September 20, 2024 22:23
@ashrithagoramane ashrithagoramane marked this pull request as ready for review September 23, 2024 22:50
@ashrithagoramane ashrithagoramane requested review from shk3, dfinninger, danielfritsch and siddarthapaladugu and removed request for shk3 September 23, 2024 22:50
Copy link
Collaborator

@shk3 shk3 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I left some comments that need to address. Also, can you rename the PR subject to a one-line summary of the change? The subject will be part of the commit history once the PR is merged.

venv.go Outdated
}
}(stream)
*o = fmt.Sprint(buff.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This step could have concurrency issue and race condition with line 248,249 when the main routine dumps the streams into the output strings.

Have you considered https://pkg.go.dev/io#TeeReader? It might need some plumbing to get it work, but using a buffer to collect output is probably much safer than dealing with strings in a multithread context.

In fact, if I had time, I would consider making CommandOutput.Stderr and CommandOutput.Stdout buffers, so we can write to the output files once a while to avoid empty log files when ansible puller crashed, but this would be for future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The real issue is on the string write part on CommandOutput.Stderr and outString. So in the modified implementation, the concurrency issue still exists. Sorry that my original comment on the streamOutput function was a bit misleading.

Actually, reading this part of code more closely, I realize the previous statement about race condition isn't correct. This part actually branches and ends when c.StreamOutput is set, so CommandOutput.Stderr and CommandOutput.Stdout won't be touched by two routines. Sorry for the confusion here caused by the bad readability of the legacy code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a minor point about ignoring the errors returned by cmd.StdoutPipe() and cmd.StderrPipe(), but this is an existing issue in the code, and I'm fine with leaving it out of the scope of this PR.

@ashrithagoramane ashrithagoramane changed the title Bugfix/debug logs Fixed the run output log files to be populated when debug=true Sep 26, 2024
Copy link
Collaborator

@shk3 shk3 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Once we address the two nits I left, I will merge this PR. Thanks again for the contribution!

@shk3 shk3 merged commit cc11235 into master Sep 28, 2024
2 checks passed
@shk3 shk3 deleted the bugfix/debug_logs branch September 28, 2024 01:04
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.

2 participants