elliotchance / sshtunnel

🚇 Ultra simple SSH tunnelling for Go programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Start server without go routine?

eleijonmarck opened this issue · comments

Hello, thank you again for creating this module

// Start the server in the background. You will need to wait a
// small amount of time for it to bind to the localhost port
// before you can start sending connections.
go tunnel.Start()
time.Sleep(100 * time.Millisecond)

In the example we start the tunnel with a goroutine. Does this have to be put on a greenthread or could it be started with the goroutine.

Why I am asking is that we are experiencing errors from the tunnel.Start() call that we want to catch as errors.
But we are unable to do that

It doesn't have to be in a separate routine but it is blocking so your application wont be able to proceed until the SSH is closed (which is probably not what you want).

Perhaps you can provide a larger part of your sample code that is failing?

@elliotchance thanks for getting back on the issue.

We solved it by:

	go func() {
		err := tunnel.Start()
		if err != nil {
			log.Fatalf("unable to start tunnel with error: %e", err)
		}
	}()

The example has a "somewhat" hidden error that is uncaught. In the goroutine we want to catch the error, to be able to use it. So the above code, is how we solved it for us.
Maybe someone could get help from this.