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

multi connections #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

yefriddavid
Copy link

@yefriddavid yefriddavid commented Oct 7, 2019

multi connections had error, with several request.


This change is Reviewable

}

func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string) *SSHTunnel {
func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string, localPort string) *SSHTunnel {
Copy link
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.

_, 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
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"


go func(writer, reader net.Conn) {
defer writer.Close()
defer reader.Close()
Copy link
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.

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

Choose a reason for hiding this comment

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

As noted above.

}

if retry > 1 {
tunnel.logf("Retry server: %s", strconv.Itoa(retry))
Copy link
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