[MM-60307] Check if session is nil before calling UpdateLastActivityAtIfNeeded (#28254)

Этот коммит содержится в:
Ben Schumacher
2024-09-26 13:52:59 +02:00
коммит произвёл GitHub
родитель 9900151fb6
Коммит 20ed58906a
2 изменённых файлов: 9 добавлений и 5 удалений

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

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

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

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