elliotchance / sshtunnel

🚇 Ultra simple SSH tunnelling for Go programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question on having a tunnel open

eleijonmarck opened this issue · comments

Hey,

thank you so much of the sshtunnel.

Is it possible to get more info on whether one needs to close the connection.

...
// 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)
...
// ...

is the example, I understand that maybe we should have a defer tunnel.Close()
but is that handled by the library itself?

...
// 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()
defer tunnel.Close()
time.Sleep(100 * time.Millisecond)
...
// ...

error

close signal received, closing...
panic: sync: negative WaitGroup counter

It doesn't handle closes automatically. The issue in versions of this package between v1.0.1 and 1.1.0 is that the WaitGroup was implemented incorrectly; the counter was never incremented to begin with.

The latest version (currently v1.1.1) does not use the sync package anymore. Instead the tunnel is kept alive using a new function that waits for new connections and Close() behaves as expected.

@isaaguilar thank you!
I am using v1.1.0 I see now.

will get back when I have tested it with Closing the tunnel.

Amazing now it works to close the tunnels

@isaaguilar
Now that I have the ability to Close the tunnel. I am experiencing a bit of error logs from the tunnel implementation.

	// 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()
	defer func() {
		time.Sleep(5 * time.Second)
		tunnel.Close()
	}()

Even if I wait 5 seconds for the tunnel to get any io.Copys out of the way (and I am not creating anything or so) I still get an error of io.Copy

2020/09/22 16:44:33.035361 accepted connection
2020/09/22 16:44:33.035380 listening for new connections...
2020/09/22 16:44:33.076055 connected to 11.11.11.11:22 (1 of 2)
2020/09/22 16:44:33.078677 connected to 22.22.22.22:22 (2 of 2)
2020/09/22 16:44:39.385185 close signal received, closing...
2020/09/22 16:44:39.385195 closing the netConn (1 of 2)
2020/09/22 16:44:39.385304 io.Copy error: read tcp 127.0.0.1:2000->127.0.0.1:40330: use of closed network connection
2020/09/22 16:44:39.385311 closing the netConn (2 of 2)
2020/09/22 16:44:39.385416 closing the serverConn (1 of 1)
2020/09/22 16:44:39.386128 tunnel closed

Please open a new ticket.

will do