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

Fix redirecting WslLaunch's output to a file #29

Merged
merged 9 commits into from
Jan 26, 2023

Conversation

EduardGomezEscandell
Copy link
Collaborator

@EduardGomezEscandell EduardGomezEscandell commented Jan 19, 2023

Passing a real file descriptor to WslLaunch does not write to a file for some reason, so I have to stick an intermediate pipe in there. This pull request does two things that should have probably been two separate PR, but became too intertwined:

  • Refactors Cmd so that it more closely resembles the stdlib. See commit
    Brought (*distro).Cmd closer to the standard library for more details.
  • Adds tests that fail, proving that we do not write to file
  • Adds the intermediate pipe, making the tests pass.

WSL-401

@EduardGomezEscandell EduardGomezEscandell changed the title In exec: Removed optimized file redirection Working on fixing redirecting to file Jan 20, 2023
@EduardGomezEscandell EduardGomezEscandell changed the title Working on fixing redirecting to file Working on fixing redirecting to file WslLaunch's output to a file Jan 20, 2023
@EduardGomezEscandell EduardGomezEscandell force-pushed the fix-exec-output-to-file branch 4 times, most recently from aa3d4a6 to a047622 Compare January 20, 2023 13:22
@EduardGomezEscandell EduardGomezEscandell self-assigned this Jan 20, 2023
@EduardGomezEscandell EduardGomezEscandell changed the title Working on fixing redirecting to file WslLaunch's output to a file Fix redirecting WslLaunch's output to a file Jan 20, 2023
@EduardGomezEscandell EduardGomezEscandell marked this pull request as ready for review January 20, 2023 13:36
@EduardGomezEscandell EduardGomezEscandell added the bug Something isn't working label Jan 20, 2023
@EduardGomezEscandell EduardGomezEscandell removed the request for review from didrocks January 20, 2023 17:04
@EduardGomezEscandell EduardGomezEscandell marked this pull request as draft January 20, 2023 17:04
@EduardGomezEscandell EduardGomezEscandell marked this pull request as ready for review January 23, 2023 08:03
@EduardGomezEscandell EduardGomezEscandell force-pushed the fix-exec-output-to-file branch 2 times, most recently from 88c4358 to 56bf249 Compare January 23, 2023 10:50
@EduardGomezEscandell EduardGomezEscandell requested review from didrocks and removed request for didrocks January 23, 2023 11:45
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

I can’t say I grocked every single details, but here is my general feedbacks. My main concern is the last comment (about returning nil if the command was running on WSL side, but failed). I know we discussed it but rereading it and seeing it back in tests, I’m less sure nowdays this is the right call.

api_windows.go Show resolved Hide resolved
examples/demo.go Outdated Show resolved Hide resolved
examples/demo.go Outdated Show resolved Hide resolved
exec.go Outdated Show resolved Hide resolved
exec.go Outdated Show resolved Hide resolved
exec_test.go Show resolved Hide resolved
exec_test.go Show resolved Hide resolved
main_test.go Outdated Show resolved Hide resolved
shell.go Outdated Show resolved Hide resolved
shell.go Outdated Show resolved Hide resolved
@EduardGomezEscandell EduardGomezEscandell force-pushed the fix-exec-output-to-file branch 2 times, most recently from ffb01de to b602a90 Compare January 26, 2023 09:18
@EduardGomezEscandell
Copy link
Collaborator Author

EduardGomezEscandell commented Jan 26, 2023

Forced pushed to rebase to main. Also used the oportunity to strategically squash commits so that they make sense once this branch is merged to main.

exec_test.go Outdated Show resolved Hide resolved
shell.go Show resolved Hide resolved
shell.go Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

still some discussions needed, but getting there!

@EduardGomezEscandell EduardGomezEscandell force-pushed the fix-exec-output-to-file branch 3 times, most recently from 3b1459c to 65f8ee0 Compare January 26, 2023 14:08
The WSL API doesn't allow writing to a file directly without an
intermediate pipe. Since pipes are also represented as an
*os.File, we have no way of distinguishing the two to treat them
differently.

These tests demonstrate this failure, although they are skipped for now
until a fix is found.
The main implication is that we offload responsabilities to the stdlib:
- We can use os.Process utils instead of our own implementation
- We can use exec.ExitError

An adjacent change: since wsl.ExitError no longer exists,
(*distro).Shell had to be rethought when it comes to its return values.

I decided to create a ShellError that contains the exit code.
Stdout and Stderr pipes were being read from before the process
finished, so they were sometimes empty.
We know that the WSL API doesn't allow writing to a file directly
without an intermediate pipe. Since pipes are also represented as an
*os.File, we have to distinguish the two with the Win32 API.

This fixes this problem and removes the Skip in the tests
Sometimes WSL takes a while to boot up, making some timeouts trigger for
even the simplest commands. Keeping the test distro alive during the
test should prevent this.
Seems like the Azure machine is quite slow.
examples/demo.go Outdated Show resolved Hide resolved
exec_test.go Outdated Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Ok, 2 remaining ones and we are done for good with this branch IMHO!

@EduardGomezEscandell EduardGomezEscandell merged commit 8ef784b into main Jan 26, 2023
@EduardGomezEscandell EduardGomezEscandell deleted the fix-exec-output-to-file branch January 26, 2023 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants