From ce314425d1e1ab5703c41510a0dba569fb6ffad3 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Oct 2017 14:02:33 -0700 Subject: Fix webconn shutdown race (#7631) * fix webconn shutdown race * make sure writePump returns promptly if readPump returns first * fix app shutdown race * minor improvement --- app/web_conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/web_conn.go') diff --git a/app/web_conn.go b/app/web_conn.go index 92b54723a..1c74e65a5 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -59,7 +59,7 @@ func (a *App) NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.Tra UserId: session.UserId, T: t, Locale: locale, - endWritePump: make(chan struct{}, 1), + endWritePump: make(chan struct{}, 2), pumpFinished: make(chan struct{}, 1), } @@ -111,13 +111,14 @@ func (c *WebConn) Pump() { ch <- struct{}{} }() c.readPump() + c.endWritePump <- struct{}{} <-ch + c.App.HubUnregister(c) c.pumpFinished <- struct{}{} } func (c *WebConn) readPump() { defer func() { - c.App.HubUnregister(c) c.WebSocket.Close() }() c.WebSocket.SetReadLimit(model.SOCKET_MAX_MESSAGE_SIZE_KB) -- cgit v1.2.3-1-g7c22