Skip to content

Commit

Permalink
Use internal.MutexByRoom
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Jun 28, 2021
1 parent 6e6f026 commit 138cddc
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions federationapi/routing/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,18 +620,13 @@ func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserv
return gomatrixserverlib.Allowed(e, &authUsingState)
}

var processEventWithMissingStateMutexes = map[string]*sync.Mutex{}
var processEventWithMissingStateMutexes = &internal.MutexByRoom{}

func (t *txnReq) processEventWithMissingState(
ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion,
) error {
mu, ok := processEventWithMissingStateMutexes[e.RoomID()]
if !ok {
processEventWithMissingStateMutexes[e.RoomID()] = &sync.Mutex{}
mu = processEventWithMissingStateMutexes[e.RoomID()]
}
mu.Lock()
defer mu.Unlock()
processEventWithMissingStateMutexes.Lock(e.RoomID())
defer processEventWithMissingStateMutexes.Unlock(e.RoomID())

// Do this with a fresh context, so that we keep working even if the
// original request times out. With any luck, by the time the remote
Expand Down

0 comments on commit 138cddc

Please sign in to comment.