Avoid race conditions, remove unreachable code

This commit is contained in:
Till Faelligen 2022-10-28 10:50:33 +02:00
parent 2999559982
commit da215c2f1d
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
5 changed files with 7 additions and 2 deletions

View file

@ -80,6 +80,7 @@ func (p *InviteStreamProvider) IncrementalSync(
if _, ok := req.Response.Rooms.Join[roomID]; ok {
continue
}
lr := types.NewLeaveResponse()
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{

View file

@ -128,7 +128,6 @@ func ToToken(provider StreamProvider, position types.StreamPosition) types.Strea
default:
panic(fmt.Sprintf("unknown stream provider: %T", t))
}
return types.StreamingToken{}
}
func IncrementalPositions(provider StreamProvider, current, since types.StreamingToken) (types.StreamPosition, types.StreamPosition) {
@ -154,5 +153,4 @@ func IncrementalPositions(provider StreamProvider, current, since types.Streamin
default:
panic(fmt.Sprintf("unknown stream provider: %T", t))
}
return 0, 0
}

View file

@ -21,6 +21,7 @@ import (
"math"
"net/http"
"strconv"
"sync"
"time"
"github.com/matrix-org/gomatrixserverlib"
@ -101,6 +102,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
Rooms: make(map[string]string), // Populated by the PDU stream
WantFullState: wantFullState, //
MembershipChanges: make(map[string]struct{}), // Populated by the PDU stream
SyncMu: &sync.Mutex{},
}, nil
}

View file

@ -326,6 +326,8 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
succeeded = err == nil
sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
}()
syncReq.SyncMu.Lock()
defer syncReq.SyncMu.Unlock()
return f(snapshot)
}

View file

@ -2,6 +2,7 @@ package types
import (
"context"
"sync"
"time"
"github.com/matrix-org/gomatrixserverlib"
@ -26,6 +27,7 @@ type SyncRequest struct {
MembershipChanges map[string]struct{}
// Updated by the PDU stream.
IgnoredUsers IgnoredUsers
SyncMu *sync.Mutex
}
func (r *SyncRequest) IsRoomPresent(roomID string) bool {