Don't sleep for 5 seconds when creating portal for join via link

This commit is contained in:
Tulir Asokan 2023-06-10 01:19:00 +03:00
parent 7c33ed04c4
commit 5c5633548f
2 changed files with 10 additions and 2 deletions

View file

@ -566,6 +566,12 @@ func (prov *ProvisioningAPI) JoinGroup(w http.ResponseWriter, r *http.Request) {
if info == nil {
return
}
user.groupJoinLock.Lock()
user.skipGroupCreateDelay = info.JID
defer func() {
user.skipGroupCreateDelay = types.EmptyJID
user.groupJoinLock.Unlock()
}()
inviteCode, _ := mux.Vars(r)["inviteCode"]
if jid, err := user.Client.JoinGroupWithLink(inviteCode); err != nil {
jsonResponse(w, http.StatusInternalServerError, Error{

View file

@ -95,7 +95,9 @@ type User struct {
resyncQueueLock sync.Mutex
nextResync time.Time
createKeyDedup string
createKeyDedup string
skipGroupCreateDelay types.JID
groupJoinLock sync.Mutex
}
type resyncQueueItem struct {
@ -1304,7 +1306,7 @@ func (user *User) markUnread(portal *Portal, unread bool) {
func (user *User) handleGroupCreate(evt *events.JoinedGroup) {
portal := user.GetPortalByJID(evt.JID)
if evt.CreateKey == "" && len(portal.MXID) == 0 {
if evt.CreateKey == "" && len(portal.MXID) == 0 && portal.Key.JID != user.skipGroupCreateDelay {
user.log.Debugfln("Delaying handling group create with empty key to avoid race conditions")
time.Sleep(5 * time.Second)
}