summaryrefslogtreecommitdiffstats
path: root/app/web_hub.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-04 13:09:41 -0700
committerGitHub <noreply@github.com>2017-10-04 13:09:41 -0700
commit07777f5ff9e0bde26abd0288164e5f73b6da992a (patch)
treeb0aa1eff510d1531d2924522e0e6f0e9bfd7ac29 /app/web_hub.go
parentdc9b1a1d6a0fe7ad2e18597cb46f3874736b4b40 (diff)
downloadchat-07777f5ff9e0bde26abd0288164e5f73b6da992a.tar.gz
chat-07777f5ff9e0bde26abd0288164e5f73b6da992a.tar.bz2
chat-07777f5ff9e0bde26abd0288164e5f73b6da992a.zip
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
Diffstat (limited to 'app/web_hub.go')
-rw-r--r--app/web_hub.go10
1 files changed, 7 insertions, 3 deletions
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
}