From be440d635d37963e0ade26782db06206013db905 Mon Sep 17 00:00:00 2001 From: folbricht Date: Wed, 20 Apr 2016 15:58:07 -0600 Subject: [PATCH] Close the connection on the server when the client closes it first When the client closes the connection, the server will read EOF. In that case the connection should be closed on the server as well. Without this change the server goroutine will go into an infinite loop when the client closes the connection. It'll try to read, get an EOF, then "continue", go back to read, get another EOF and so on. That takes 100% CPU in this situation. --- conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 7dbda83..6ae9e9f 100644 --- a/conn.go +++ b/conn.go @@ -69,7 +69,7 @@ func (conn *Conn) Serve() { line, err := conn.controlReader.ReadString('\n') if err != nil { if err == io.EOF { - continue + break } conn.logger.Print(fmt.Sprintln("read error:", err))