[MM-58500] Turn off PostedAck when the connection is no longer registered (#27212)

* [MM-58500] Turn off PostedAck when the connection is no longer registered

* Expose active and just check for active instead
Этот коммит содержится в:
Devin Binnie
2024-06-03 09:44:53 -04:00
коммит произвёл GitHub
родитель 4163db4e5e
Коммит 4ec50a7ddd
5 изменённых файлов: 42 добавлений и 22 удалений

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

@@ -389,7 +389,7 @@ func (h *Hub) Start() {
conns := connIndex.ForUser(webSessionMessage.userID)
var isRegistered bool
for _, conn := range conns {
if !conn.active.Load() {
if !conn.Active.Load() {
continue
}
if conn.GetSessionToken() == webSessionMessage.sessionToken {
@@ -419,7 +419,7 @@ func (h *Hub) Start() {
// Mark the current one as active.
// There is no need to check if it was inactive or not,
// we will anyways need to make it active.
webConn.active.Store(true)
webConn.Active.Store(true)
connIndex.Add(webConn)
atomic.StoreInt64(&h.connectionCount, int64(connIndex.AllActive()))
@@ -434,7 +434,7 @@ func (h *Hub) Start() {
case webConn := <-h.unregister:
// If already removed (via queue full), then removing again becomes a noop.
// But if not removed, mark inactive.
webConn.active.Store(false)
webConn.Active.Store(false)
atomic.StoreInt64(&h.connectionCount, int64(connIndex.AllActive()))
@@ -471,7 +471,7 @@ func (h *Hub) Start() {
}
var latestActivity int64
for _, conn := range conns {
if !conn.active.Load() {
if !conn.Active.Load() {
continue
}
if conn.lastUserActivityAt > latestActivity {
@@ -491,7 +491,7 @@ func (h *Hub) Start() {
}
case activity := <-h.activity:
for _, webConn := range connIndex.ForUser(activity.userID) {
if !webConn.active.Load() {
if !webConn.Active.Load() {
continue
}
if webConn.GetSessionToken() == activity.sessionToken {
@@ -506,7 +506,7 @@ func (h *Hub) Start() {
case directMsg.conn.send <- directMsg.msg:
default:
// Don't log the warning if it's an inactive connection.
if directMsg.conn.active.Load() {
if directMsg.conn.Active.Load() {
mlog.Error("webhub.broadcast: cannot send, closing websocket for user",
mlog.String("user_id", directMsg.conn.UserId),
mlog.String("conn_id", directMsg.conn.GetConnectionID()))
@@ -533,7 +533,7 @@ func (h *Hub) Start() {
case webConn.send <- h.runBroadcastHooks(msg, webConn, broadcastHooks, broadcastHookArgs):
default:
// Don't log the warning if it's an inactive connection.
if webConn.active.Load() {
if webConn.Active.Load() {
mlog.Error("webhub.broadcast: cannot send, closing websocket for user",
mlog.String("user_id", webConn.UserId),
mlog.String("conn_id", webConn.GetConnectionID()))
@@ -601,7 +601,7 @@ func (h *Hub) Start() {
// are inactive or not.
func areAllInactive(conns []*WebConn) bool {
for _, conn := range conns {
if conn.active.Load() {
if conn.Active.Load() {
return false
}
}
@@ -689,7 +689,7 @@ func (i *hubConnectionIndex) ForUser(id string) []*WebConn {
func (i *hubConnectionIndex) ForUserActiveCount(id string) int {
cnt := 0
for _, conn := range i.ForUser(id) {
if conn.active.Load() {
if conn.Active.Load() {
cnt++
}
}
@@ -714,7 +714,7 @@ func (i *hubConnectionIndex) RemoveInactiveByConnectionID(userID, connectionID s
return nil
}
for _, conn := range i.ForUser(userID) {
if conn.GetConnectionID() == connectionID && !conn.active.Load() {
if conn.GetConnectionID() == connectionID && !conn.Active.Load() {
i.Remove(conn)
return conn
}
@@ -727,7 +727,7 @@ func (i *hubConnectionIndex) RemoveInactiveByConnectionID(userID, connectionID s
func (i *hubConnectionIndex) RemoveInactiveConnections() {
now := model.GetMillis()
for conn := range i.byConnection {
if !conn.active.Load() && now-conn.lastUserActivityAt > i.staleThreshold.Milliseconds() {
if !conn.Active.Load() && now-conn.lastUserActivityAt > i.staleThreshold.Milliseconds() {
i.Remove(conn)
}
}
@@ -739,7 +739,7 @@ func (i *hubConnectionIndex) RemoveInactiveConnections() {
func (i *hubConnectionIndex) AllActive() int {
cnt := 0
for conn := range i.byConnection {
if conn.active.Load() {
if conn.Active.Load() {
cnt++
}
}