From 07777f5ff9e0bde26abd0288164e5f73b6da992a Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 4 Oct 2017 13:09:41 -0700 Subject: Fix races / finally remove global app for good (#7570) * finally remove global app for good * test compilation fixes * fix races * fix deadlock * wake up write pump so it doesn't take forever to clean up --- app/web_hub.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/web_hub.go') diff --git a/app/web_hub.go b/app/web_hub.go index 0a70cb6d1..1525dfbba 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -36,6 +36,7 @@ type Hub struct { unregister chan *WebConn broadcast chan *model.WebSocketEvent stop chan string + didStop chan struct{} invalidateUser chan string ExplicitStop bool goroutineId int @@ -44,11 +45,12 @@ type Hub struct { func (a *App) NewWebHub() *Hub { return &Hub{ app: a, - register: make(chan *WebConn), - unregister: make(chan *WebConn), + register: make(chan *WebConn, 1), + unregister: make(chan *WebConn, 1), connections: make([]*WebConn, 0, model.SESSION_CACHE_SIZE), broadcast: make(chan *model.WebSocketEvent, BROADCAST_QUEUE_SIZE), stop: make(chan string), + didStop: make(chan struct{}, 1), invalidateUser: make(chan string), ExplicitStop: false, } @@ -348,6 +350,7 @@ func getGoroutineId() int { func (h *Hub) Stop() { h.stop <- "all" + <-h.didStop } func (h *Hub) Start() { @@ -428,9 +431,10 @@ func (h *Hub) Start() { case <-h.stop: for _, webCon := range h.connections { - webCon.WebSocket.Close() + webCon.Close() } h.ExplicitStop = true + h.didStop <- struct{}{} return } -- cgit v1.2.3-1-g7c22