From 5e69ce099f521aa49fc267c62235c003eae530ff Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 3 Oct 2017 10:53:53 -0500 Subject: Goroutine wranglin (#7556) * goroutine wranglin * synchronize WebConn.WritePump --- app/web_conn.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'app/web_conn.go') diff --git a/app/web_conn.go b/app/web_conn.go index f5644ce17..5f66d9a51 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -44,10 +44,10 @@ type WebConn struct { func (a *App) NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn { if len(session.UserId) > 0 { - go func() { + a.Go(func() { a.SetStatusOnline(session.UserId, session.Id, false) a.UpdateLastActivityAtIfNeeded(session) - }() + }) } wc := &WebConn{ @@ -94,6 +94,16 @@ func (c *WebConn) SetSession(v *model.Session) { c.session.Store(v) } +func (c *WebConn) Pump() { + ch := make(chan struct{}, 1) + go func() { + c.WritePump() + ch <- struct{}{} + }() + c.ReadPump() + <-ch +} + func (c *WebConn) ReadPump() { defer func() { c.App.HubUnregister(c) @@ -104,7 +114,9 @@ func (c *WebConn) ReadPump() { c.WebSocket.SetPongHandler(func(string) error { c.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT)) if c.IsAuthenticated() { - go c.App.SetStatusAwayIfNeeded(c.UserId, false) + c.App.Go(func() { + c.App.SetStatusAwayIfNeeded(c.UserId, false) + }) } return nil }) @@ -191,7 +203,9 @@ func (c *WebConn) WritePump() { } if c.App.Metrics != nil { - go c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType()) + c.App.Go(func() { + c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType()) + }) } } -- cgit v1.2.3-1-g7c22