Skip to content

Commit

Permalink
Merge pull request #311 from matrix-org/kegan/deadlock-xact
Browse files Browse the repository at this point in the history
Reduce mutex contention on callbacks
  • Loading branch information
kegsay committed Sep 21, 2023
2 parents e75a462 + 4114118 commit 6fe9b18
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sync2/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,25 @@ func (h *PollerMap) DeviceIDs(userID string) []string {

func (h *PollerMap) ExpirePollers(pids []PollerID) int {
h.pollerMu.Lock()
defer h.pollerMu.Unlock()
numTerminated := 0
var pollersToTerminate []*poller
for _, pid := range pids {
p, ok := h.Pollers[pid]
if !ok || p.terminated.Load() {
continue
}
pollersToTerminate = append(pollersToTerminate, p)
}
h.pollerMu.Unlock()
// now terminate the pollers.
for _, p := range pollersToTerminate {
p.Terminate()
// Ensure that we won't recreate this poller on startup. If it reappears later,
// we'll make another EnsurePolling call which will recreate the poller.
h.callbacks.OnExpiredToken(context.Background(), hashToken(p.accessToken), p.userID, p.deviceID)
numTerminated++
}

return numTerminated
}

Expand Down

0 comments on commit 6fe9b18

Please sign in to comment.