From 5717c7ca2990cf6af2e1f98c8192177768905c67 Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 30 Apr 2019 17:45:44 +0200 Subject: [PATCH 1/2] FIX #18 server close connections I am not sure this really fixes the problem (but it seems to) --- cmd/circolog-tail/main.go | 2 +- cmd/circologd/http_log.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/circolog-tail/main.go b/cmd/circolog-tail/main.go index e0ecfd2..74a7a7c 100644 --- a/cmd/circolog-tail/main.go +++ b/cmd/circolog-tail/main.go @@ -149,7 +149,7 @@ func main() { select { case <-done: log.Println("Successfully close") - case <-time.After(1 * time.Second): + case <-time.After(5 * time.Second): log.Println("Forced close") } return diff --git a/cmd/circologd/http_log.go b/cmd/circologd/http_log.go index 712d15a..bdb63c8 100644 --- a/cmd/circologd/http_log.go +++ b/cmd/circologd/http_log.go @@ -153,6 +153,14 @@ func getWSHandler(hub circolog.Hub) http.HandlerFunc { hub.Unregister <- c conn.Close() }() + go func() { + for { + _, _, err := conn.ReadMessage() + if err != nil { + return + } + } + }() for { select { case message, ok := <-c.Messages: From aea09d94bfd45c0b8938b120f77b6acc362b73bc Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 30 Apr 2019 17:56:13 +0200 Subject: [PATCH 2/2] refs #18 cleans sockets --- cmd/circologd/http_log.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/circologd/http_log.go b/cmd/circologd/http_log.go index bdb63c8..1678e87 100644 --- a/cmd/circologd/http_log.go +++ b/cmd/circologd/http_log.go @@ -157,6 +157,7 @@ func getWSHandler(hub circolog.Hub) http.HandlerFunc { for { _, _, err := conn.ReadMessage() if err != nil { + conn.Close() return } }