From d0ab23b879be5391545b9480d39670d69a78023e Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Tue, 17 Apr 2018 16:40:56 +0200 Subject: [PATCH] fix(client): wait for interrupt signal to close connection --- cmd/vex/main.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/vex/main.go b/cmd/vex/main.go index e479fb3..d2eca91 100644 --- a/cmd/vex/main.go +++ b/cmd/vex/main.go @@ -106,20 +106,24 @@ func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) - for { - // Open a (local) connection to localEndpoint whose content will be forwarded so serverEndpoint - local, err := net.Dial("tcp", localEndpoint.String()) - if err != nil { - log.Fatalln(fmt.Printf("Dial INTO local service error: %s", err)) - } - - client, err := listener.Accept() - if err != nil { - log.Fatalln(err) + go func() { + for { + // Open a (local) connection to localEndpoint whose content will be forwarded so serverEndpoint + local, err := net.Dial("tcp", localEndpoint.String()) + if err != nil { + log.Fatalln(fmt.Printf("Dial INTO local service error: %s", err)) + } + + client, err := listener.Accept() + if err != nil { + log.Fatalln(err) + } + + go handleClient(client, local) } + }() - go handleClient(client, local) - } + <-c } func handleClient(client net.Conn, remote net.Conn) {