Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Fix the problem that the terminal exit fails #8189

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

ssongliu
Copy link
Member

No description provided.

Copy link

f2c-ci-robot bot commented Mar 19, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

}
dt := time.Now().Add(time.Second)
_ = wsConn.WriteControl(websocket.CloseMessage, nil, dt)

}

func loadRedisInitCmd(c *gin.Context) (string, string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

There seem to be no significant changes between the two versions of the provided Go code that could cause issues or performance bottlenecks. The primary difference appears to be in handling WebSocket connections within different methods, WsSsh and ContainerWsSSH, without substantial modification.

Here are a few observations:

  1. Both functions use the same logic for closing the websocket connection using the WriteControl method with a CloseMessage.
  2. They handle errors similarly by calling the same function (wshandleError) followed by returning if it returns true.
  3. There is slight code repetition in both functions, which could theoretically be optimized slightly.

For further improvement:

  • Code DRYness: Combine similar sections of code, especially around error handling, into helper functions where applicable.
  • Documentation Updates: Ensure comments and documentation accuratelyreflect the current functionality, especially regarding when the QuitChan is handled.

In summary, the code remains mostly functional and should work correctly as implemented. However, there's scope for minor clean-up related to redundancy and improved readability.

term.value.write('The connection has been disconnected.');
term.value.write(ev.reason);
term.value?.write('The connection has been disconnected.');
term.value?.write(ev.reason);
};

const isWsOpen = () => {
Copy link
Member

Choose a reason for hiding this comment

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

There are no significant irregularities, potential issues, or optimization suggestions in the provided code changes. The most noticeable update from one line to another is using Number() when clearing the timer and ensuring that term.value exists before calling methods on it to avoid potential errors.

@@ -100,4 +100,5 @@ func (lcmd *LocalCommand) Wait(quitChan chan bool) {
global.LOG.Errorf("ssh session wait failed, err: %v", err)
setQuit(quitChan)
}
setQuit(quitChan)
}
Copy link
Member

Choose a reason for hiding this comment

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

The provided code snippet is mostly correct, but there are some minor improvements and clarifications that can be made:

Improvements

  1. Redundant Line: The line setQuit(quitChan) appears twice at different positions in the function. While it's not strictly necessary, you might want to decide whether one of these should be removed.

  2. Logical Clarity: Consider adding a comment above this block explaining its purpose. This helps improve readability.

  3. Error Handling: Ensure that err is defined before using it to prevent potential runtime errors.

Here's an updated version with these considerations:

@@ -97,5 +96,8 @@ func (lcmd *LocalCommand) Wait(quitChan chan bool) {
         global.LOG.Errorf("ssh session wait failed, err: %v", err)
         setQuit(quitChan)
     }
+
+    // Function waits for SSH session to complete, handling any errors encountered.
+    // It also ensures that the quit channel is properly closed if an error occurs.
+    // Note: setQuit(quitChan) is called again here to ensure proper resource management.
+    setQuit(quitChan)
 }

Optimization Suggestions:

  • Avoid Redundancy: If only the first call to setQuit(quitChan) is needed, consider removing the second call. Only do what needs to be done once unless both calls have specific purposes.

  • Consistent Naming: Consistently name variables and functions to improve maintainability and reduce bugs.

By making these adjustments, the code becomes more readable and potentially more efficient.

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Mar 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

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

@f2c-ci-robot f2c-ci-robot bot merged commit 79eb028 into dev Mar 19, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev-v2@fix_terminal_exit branch March 19, 2025 03:43
@JohnNiang JohnNiang linked an issue Mar 19, 2025 that may be closed by this pull request
gcsong023 pushed a commit to gcsong023/1Panel that referenced this pull request Mar 27, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] The CPU is inexplicably consumed and cannot be downloaded.
3 participants