Reusing tcp connections on tunnels

146 views
Skip to first unread message

XXX ZZZ

unread,
Jan 16, 2020, 3:07:28 PM1/16/20
to golang-nuts
Hello,

I'm trying to write an application that will basically serve as a tunnel between some servers outside our network and our internal servers. For this I've started using a snippet that creates a tcp listener and then dials to a remote host. Code is shown here:

https://play.golang.org/p/4wjCZFXq6Yg

The code works just fine, however every time it gets a new request it dials a new connection to the remote host, and then after all data has been forwarded to both sides it closes them. I'm no expert on networking but this looks like its just opening/closing tcp connections instead of just reusing them, is this correct? if so, what would be the correct way of resuing the connection?

Thanks!

hao dong

unread,
Jan 16, 2020, 8:59:06 PM1/16/20
to golang-nuts
I don't think every net.Dial() creates an actually tcp connection to a server, this func is just an abstract of system call. Desingers of Go are so clever that will not do this stupid thing. I think I will make a test of that. 

Kevin Chadwick

unread,
Jan 17, 2020, 7:51:27 AM1/17/20
to golan...@googlegroups.com
If you look at OpenSSH they have tcp keepalives as an option to inform routers to not drop the state and encrypted keep alives that aren't spoofable. There will also be timeout settings that people will want to modify. All of this is app specific DDOS/efficiency/up time/ease of use/timely informed connection loss etc.

For example net/http has ease of use defaults not suitable for production but behind app engine they do not matter much. When people deploy golang on an OS or compute engine then they need to consider the timeouts etc.

Perhaps you understand all this but maybe not?
Reply all
Reply to author
Forward
0 new messages