mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-52550] platform/web_conn: fix a possible data race issue (#23255)
* platform/web_conn: fix a possible data race issue * reflect review comments --------- Co-authored-by: Ibrahim Serdar Acikgoz <ibrahim@ibrahims-mac.local> Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
d860548a76
commit
d030f681eb
@ -171,10 +171,12 @@ func (ps *PlatformService) PopulateWebConnConfig(s *model.Session, cfg *WebConnC
|
||||
|
||||
// NewWebConn returns a new WebConn instance.
|
||||
func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runner HookRunner) *WebConn {
|
||||
userID := cfg.Session.UserId
|
||||
session := cfg.Session
|
||||
if cfg.Session.UserId != "" {
|
||||
ps.Go(func() {
|
||||
ps.SetStatusOnline(cfg.Session.UserId, false)
|
||||
ps.UpdateLastActivityAtIfNeeded(cfg.Session)
|
||||
ps.SetStatusOnline(userID, false)
|
||||
ps.UpdateLastActivityAtIfNeeded(session)
|
||||
})
|
||||
}
|
||||
|
||||
@ -232,9 +234,9 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn
|
||||
wc.SetSessionExpiresAt(cfg.Session.ExpiresAt)
|
||||
wc.SetConnectionID(cfg.ConnectionID)
|
||||
|
||||
wc.Platform.Go(func() {
|
||||
wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketConnect(wc.GetConnectionID(), wc.UserId)
|
||||
ps.Go(func() {
|
||||
runner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketConnect(wc.GetConnectionID(), userID)
|
||||
return true
|
||||
}, plugin.OnWebSocketConnectID)
|
||||
})
|
||||
@ -334,9 +336,10 @@ func (wc *WebConn) Pump() {
|
||||
wc.Platform.HubUnregister(wc)
|
||||
close(wc.pumpFinished)
|
||||
|
||||
userID := wc.UserId
|
||||
wc.Platform.Go(func() {
|
||||
wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.OnWebSocketDisconnect(wc.GetConnectionID(), wc.UserId)
|
||||
hooks.OnWebSocketDisconnect(wc.GetConnectionID(), userID)
|
||||
return true
|
||||
}, plugin.OnWebSocketDisconnectID)
|
||||
})
|
||||
@ -353,8 +356,9 @@ func (wc *WebConn) readPump() {
|
||||
return err
|
||||
}
|
||||
if wc.IsAuthenticated() {
|
||||
userID := wc.UserId
|
||||
wc.Platform.Go(func() {
|
||||
wc.Platform.SetStatusAwayIfNeeded(wc.UserId, false)
|
||||
wc.Platform.SetStatusAwayIfNeeded(userID, false)
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
@ -436,8 +436,9 @@ func (h *Hub) Start() {
|
||||
|
||||
conns := connIndex.ForUser(webConn.UserId)
|
||||
if len(conns) == 0 || areAllInactive(conns) {
|
||||
userID := webConn.UserId
|
||||
h.platform.Go(func() {
|
||||
h.platform.SetStatusOffline(webConn.UserId, false)
|
||||
h.platform.SetStatusOffline(userID, false)
|
||||
})
|
||||
continue
|
||||
}
|
||||
@ -452,8 +453,9 @@ func (h *Hub) Start() {
|
||||
}
|
||||
|
||||
if h.platform.isUserAway(latestActivity) {
|
||||
userID := webConn.UserId
|
||||
h.platform.Go(func() {
|
||||
h.platform.SetStatusLastActivityAt(webConn.UserId, latestActivity)
|
||||
h.platform.SetStatusLastActivityAt(userID, latestActivity)
|
||||
})
|
||||
}
|
||||
case userID := <-h.invalidateUser:
|
||||
|
Loading…
Reference in New Issue
Block a user