diff --git a/server/channels/app/platform/session.go b/server/channels/app/platform/session.go index 27d5f0d315..e12f22bb96 100644 --- a/server/channels/app/platform/session.go +++ b/server/channels/app/platform/session.go @@ -17,11 +17,12 @@ import ( func (ps *PlatformService) ReturnSessionToPool(session *model.Session) { if session != nil { session.Id = "" - // Once the session is retrieved from the pool, all existing prop fields are cleared. - // To avoid a race between clearing the props and accessing it, clear the props maps before returning it to the pool. + // All existing prop fields are cleared once the session is retrieved from the pool. + // To speed up that process, clear the props here to avoid doing that in the hot path. + // + // If the request handler spawns a goroutine that uses the session, it might race with this code. + // In that case, the handler should copy the session and use the copy in the goroutine. clear(session.Props) - // Also clear the team members slice to avoid a similar race condition. - clear(session.TeamMembers) ps.sessionPool.Put(session) } } diff --git a/server/channels/app/platform/web_conn.go b/server/channels/app/platform/web_conn.go index caa27dd663..af2d41b51b 100644 --- a/server/channels/app/platform/web_conn.go +++ b/server/channels/app/platform/web_conn.go @@ -253,7 +253,10 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn // Create a goroutine to avoid blocking the creation of the websocket connection. ps.Go(func() { ps.SetStatusOnline(userID, false) - ps.UpdateLastActivityAtIfNeeded(*wc.GetSession()) + session := wc.GetSession() + if session != nil { + ps.UpdateLastActivityAtIfNeeded(*session) + } }) }