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

feat: [M3-8722] - Improve weblish retry behavior #11067

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

plisiecki1
Copy link
Contributor

Description 📝

  • automatically reconnect weblish sessions that have disconnected
  • … unless it fails rapidly (more than 3 times in a 1 minute window)
  • … in which case show an error screen with as much information as we can provide
  • … where the error screen includes a button to try again.
  • focus the terminal element when starting (which is generally helpful but also prevents losing focus after a reconnect)

Previously, a failure would often just result in a spinning circle forever.

Changes 🔄

List any change relevant to the reviewer.

  • added option “action button” feature to ErrorState
  • added some helpers to Lish.tsx which may also be useful for similar enhancements to graphical lish (glish) in the future.
  • changed socket to be mutable and nullable so it can be updated when reconnecting. origSocket local variable is used to ensure that “stale” events are properly ignored.
  • moved error parsing/handling to the close handler, which also eliminates the potential for console output that too closely matches an "expired" error being interpreted as an error and breaking the session immediately.

Target release date 🗓️

TBD.

Preview 📷

Before After
M3-8722-before M3-8722-error

How to test 🧪

Prerequisites

Running linode(s).

Reproduction steps

Launch a lish session for a machine, type ^a d kill <enter>. The session will exit and show a spinning circle.

Verification steps

  • Launch a lish session for a machine, type ^a d kill <enter>. The session will reconnect.
  • Repeat, it should reconnect again.
  • Repeat, it should reconnect again.
  • Repeat, it should show an error message (if all three attempts are withing 60s).
  • Click the "Retry Connection" button. It should reconnect.
  • Ensure that the reconnected session actually works, i.e., that interaction with the terminal is successful.

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

* automatically reconnect weblish sessions that have disconnected
* … unless it fails rapidly (more than 3 times in a 1 minute window)
* … in which case show an error screen with as much information as we can provide
* … where the error screen includes a button to try again.
* focus the terminal element when starting (which is generally helpful but also prevents _losing_ focus after a reconnect)

Previously, a failure would often just result in a spinning circle forever.
@plisiecki1 plisiecki1 requested a review from a team as a code owner October 8, 2024 17:33
@plisiecki1 plisiecki1 requested review from hana-akamai and cpathipa and removed request for a team October 8, 2024 17:33
Copy link

github-actions bot commented Oct 8, 2024

Coverage Report:
Base Coverage: 87.06%
Current Coverage: 87.04%

packages/manager/src/components/ErrorState/ErrorState.tsx Outdated Show resolved Hide resolved
packages/manager/src/features/Lish/Lish.tsx Outdated Show resolved Hide resolved
packages/manager/src/features/Lish/Weblish.tsx Outdated Show resolved Hide resolved
packages/manager/src/features/Lish/Weblish.tsx Outdated Show resolved Hide resolved
…Error`.

Break the `formatError` logic into two separate function that compute the two parts of the output, and then the main function just appends them. Adopt the preferred `const x = () =>` syntax in lieu of `function x()` syntax.
* Remove comments for obvious fields
* `actionButton` => `actionButtonProps`
* Combine `try` cases when parsing errors
* Add spaces around `=>` types.
* Remove unnecessary `Optional Action Button` comment.
* Refactor error handling using new `ParsePotentialLishErrorString` and `LishErrorInterface`. This centralizes all of the code to check structure and type of errors in one place. This may also prove using for future improvements to graphical lish.
* Flatten websocket `close` handler logic from if-if-else-else structure to if-return-if-return-return.
Comment on lines 69 to 90
{
const reason = parsed?.reason;
if (parsed?.type === "error" && typeof reason === "string") {
return {
reason: reason,
grn: grn,
formatted: reason + grnFormatted,
isExpired: reason.toLowerCase() === "your session has expired."
};
}
}
{
const reason = parsed?.errors?.[0]?.reason;
if (typeof reason === "string") {
return {
reason: reason,
grn: grn,
formatted: `Error code: ${reason}${grnFormatted}`,
isExpired: reason === "expired"
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between these two cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error may take one of two different formats. {"type":"error","reason":"..."} or {"errors":[{"reason":"..."}]}. The "expired" case can occur with either format, but the message to check is slightly different. The formatting is also slightly different because the first form tends to output descriptive errors, whereas the second from outputs one-word codes. (Currently, only the second form sends grn trace information, but I wanted to leave the option of adding it to the first, so the grn is currently handled outside of those two cases.)

* Remove second error format: It turns out that it will not be too difficult to make all of the errors follow the same basic format, so we don't need two separate parsers. Yay!
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