Skip to content

multi connections#1

Open
yefriddavid wants to merge 2 commits into
elliotchance:masterfrom
yefriddavid:master
Open

multi connections#1
yefriddavid wants to merge 2 commits into
elliotchance:masterfrom
yefriddavid:master

Conversation

@yefriddavid

@yefriddavid yefriddavid commented Oct 7, 2019

Copy link
Copy Markdown

multi connections had error, with several request.


This change is Reviewable

Comment thread ssh_tunnel.go
}

func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string) *SSHTunnel {
func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string, localPort string) *SSHTunnel {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This will have to be a different constructor, such as NewSSHTunnelWithPort. Unless there is a special reason why the called needs to provide a specific port, it's much cleaner to allow hide that.

Comment thread ssh_tunnel.go
_, err := io.Copy(writer, reader)
if err != nil {
tunnel.logf("io.Copy error: %s", err)
tunnel.logf("io.Copy local to remote warm: %s", err)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is "warm" means to be "warn"? Is so it's not a warning because it will break the connection. How about "io.Copy local to remote failed: %s"

Comment thread ssh_tunnel.go

go func(writer, reader net.Conn) {
defer writer.Close()
defer reader.Close()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You are closing both connections twice.

Comment thread ssh_tunnel.go
defer reader.Close()
_, err := io.Copy(writer, reader)
if err != nil {
tunnel.logf("io.Copy remote to local warm: %s", err)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

As noted above.

Comment thread ssh_tunnel.go
}

if retry > 1 {
tunnel.logf("Retry server: %s", strconv.Itoa(retry))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There are a few things I don't like about this:

  1. This is unlimited retry. There must be a way to configure it or give it a save default (such as 3 times).
  2. It's repeated code, the same thing happens below. The retry mechanism can be moved to be a method.
  3. There's no need to print the number of failures if you have already logged each failure.

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