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
Этот коммит содержится в:
Chris
2017-10-04 13:09:41 -07:00
коммит произвёл GitHub
родитель dc9b1a1d6a
Коммит 07777f5ff9
23 изменённых файлов: 139 добавлений и 67 удалений

Просмотреть файл

@@ -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
}