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(backend): Almost empty error when wsl.exe fails. #120

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

CarlosNihelton
Copy link
Collaborator

If wsl.exe doesn't exit 0, then we read the byte buffer to find "Wsl/Service/WSL_E_DISTRO_NOT_FOUND".

By doing so we're exhausting the reader, so the last line of this function essentially assembles an empty message, because there is nothing more to retrieve from the reader.

The fix is write the buffer contents into strings and use those when comparing and generating error messages.
That could be a problem for very long outputs, but wsl.exe itself always generates short messages (currently at least).

If wsl.exe doesn't exit 0, then we read the byte buffer to find "Wsl/Service/WSL_E_DISTRO_NOT_FOUND".

By doing so we're exhausting the reader, so the last line of this function essentially assembles an empty message, because
there is nothing more to retrieve from the reader.

The fix is write the buffer contents into strings and use those when comparing and generating error messages.
@CarlosNihelton CarlosNihelton marked this pull request as ready for review September 6, 2024 15:07
@CarlosNihelton CarlosNihelton requested a review from a team as a code owner September 6, 2024 15:07
@CarlosNihelton CarlosNihelton self-assigned this Sep 6, 2024
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.

interesting edge case! Well done in finding it :)

@CarlosNihelton CarlosNihelton merged commit 049fd49 into main Sep 6, 2024
6 checks passed
@CarlosNihelton CarlosNihelton deleted the fix-empty-error branch September 6, 2024 16:32
CarlosNihelton added a commit to canonical/ubuntu-pro-for-wsl that referenced this pull request Dec 10, 2024
```
time=2024-07-24T12:17:10-07:00 level=error msg=Landscape:  skipping distro "Ubuntu-24.04" from landscape info: could not get distro "Ubuntu-24.04"'s state: could not get states of distros: exit status 1. Stdout: . Stderr:
```

That happens during construction of the status message sent to
Landscape. If we skip a distro, Landscape understands it doesn't exist
anymore and removes it from the dashboard. But that happens sometimes
when an existing distro. It seems a WSL internal error.

ubuntu/GoWSL#120 should prevent the stdout and
stderr messages to come empty as shown above.
Thus I'm updating GoWSL here.

That doesn't prevent the issue itself.

I couldn’t reproduce this outside of UP4W. I attempted building a small
binary in Go doing the same steps as GoWSL does and put it to run during
system startup in loop, rebooted the OS many times but no success. The
few times I’ve seen this happening in the logs were early during app
startup, so I suspect it may happen because some WSL internal component
is not yet ready. Thus this PR: adding one-time retry if an error
happens when attempting to retrieve a distro state.

Either that will prevent the issue once for all or at least give us more
context about what causes that error.

---

UDENG-3722
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