What is the idiomatic way in Go to timeout a TCP conversation, such as initial protocol handshake? Let's say there is a goroutine that handles the TCP conversation. I can launch it, then launch a time.After()
, then select
for both of them and if timeout was hit, proceed on doing other stuff.
However, that means that the TCP goroutine will linger on after the timeout keeping the TCP connection alive even though nobody will ever need it.