-
-
Couldn't load subscription status.
- Fork 66
feat: improve proxy SSH client management and configuration #99
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "mcp__github__get_issue" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,18 +292,24 @@ func (ssh_conf *MakeConfig) Connect() (*ssh.Session, *ssh.Client, error) { | |
| conn = result.conn | ||
| err = result.err | ||
| case <-ctx.Done(): | ||
| proxyClient.Close() | ||
| return nil, nil, fmt.Errorf("%w: %v", ErrProxyDialTimeout, ctx.Err()) | ||
| } | ||
|
|
||
| if err != nil { | ||
| proxyClient.Close() | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| ncc, chans, reqs, err := ssh.NewClientConn(conn, net.JoinHostPort(ssh_conf.Server, ssh_conf.Port), targetConfig) | ||
| if err != nil { | ||
| proxyClient.Close() | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| // Close the proxy client after successfully establishing the target connection | ||
| // The target connection (ncc) is now independent of the proxy client | ||
| proxyClient.Close() | ||
|
Comment on lines
+310
to
+312
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Closing the The comment on lines 310-311 is misleading; the target connection While this change correctly closes the To fix the resource leak on the success path, you would need a way to close the |
||
| client = ssh.NewClient(ncc, chans, reqs) | ||
|
Comment on lines
+310
to
313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Closing proxyClient breaks the target connection. Closing
This is likely causing the pipeline failures in The proxy client must remain alive for the lifetime of the target connection. Consider these alternatives: Solution 1: Store Solution 2: Return -func (ssh_conf *MakeConfig) Connect() (*ssh.Session, *ssh.Client, error) {
+func (ssh_conf *MakeConfig) Connect() (*ssh.Session, *ssh.Client, io.Closer, error) {Then callers close it after closing the client. This would be a breaking API change requiring updates to all call sites. Solution 3: Keep the current API but document that the proxy connection lifecycle is managed internally and sessions/clients must be explicitly closed by callers (remove lines 310-312). Given the breaking change implications, Solution 3 (removing lines 310-312 entirely) may be most pragmatic for now, with Solution 1 or 2 considered for a future major version.
🤖 Prompt for AI Agents |
||
| } else { | ||
| client, err = ssh.Dial(string(ssh_conf.Protocol), net.JoinHostPort(ssh_conf.Server, ssh_conf.Port), targetConfig) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding
proxyClient.Close()on these error paths is correct to prevent resource leaks, the repetition of this call in multiple places could be simplified. You could consider using adeferwith a flag to control when the client is closed. This would make the code cleaner and less prone to errors if more exit paths are added in the future.For example:
This way, you only need to manage the
closeProxyflag, and thedeferstatement handles the cleanup on all error returns automatically.