Avoid race conditions, remove unreachable code
This commit is contained in:
parent
2999559982
commit
da215c2f1d
|
@ -80,6 +80,7 @@ func (p *InviteStreamProvider) IncrementalSync(
|
||||||
if _, ok := req.Response.Rooms.Join[roomID]; ok {
|
if _, ok := req.Response.Rooms.Join[roomID]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
lr := types.NewLeaveResponse()
|
lr := types.NewLeaveResponse()
|
||||||
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
|
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
|
||||||
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
|
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
|
||||||
|
|
|
@ -128,7 +128,6 @@ func ToToken(provider StreamProvider, position types.StreamPosition) types.Strea
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown stream provider: %T", t))
|
panic(fmt.Sprintf("unknown stream provider: %T", t))
|
||||||
}
|
}
|
||||||
return types.StreamingToken{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IncrementalPositions(provider StreamProvider, current, since types.StreamingToken) (types.StreamPosition, types.StreamPosition) {
|
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:
|
default:
|
||||||
panic(fmt.Sprintf("unknown stream provider: %T", t))
|
panic(fmt.Sprintf("unknown stream provider: %T", t))
|
||||||
}
|
}
|
||||||
return 0, 0
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"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
|
Rooms: make(map[string]string), // Populated by the PDU stream
|
||||||
WantFullState: wantFullState, //
|
WantFullState: wantFullState, //
|
||||||
MembershipChanges: make(map[string]struct{}), // Populated by the PDU stream
|
MembershipChanges: make(map[string]struct{}), // Populated by the PDU stream
|
||||||
|
SyncMu: &sync.Mutex{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,6 +326,8 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
|
||||||
succeeded = err == nil
|
succeeded = err == nil
|
||||||
sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
|
sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
|
||||||
}()
|
}()
|
||||||
|
syncReq.SyncMu.Lock()
|
||||||
|
defer syncReq.SyncMu.Unlock()
|
||||||
return f(snapshot)
|
return f(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
@ -26,6 +27,7 @@ type SyncRequest struct {
|
||||||
MembershipChanges map[string]struct{}
|
MembershipChanges map[string]struct{}
|
||||||
// Updated by the PDU stream.
|
// Updated by the PDU stream.
|
||||||
IgnoredUsers IgnoredUsers
|
IgnoredUsers IgnoredUsers
|
||||||
|
SyncMu *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SyncRequest) IsRoomPresent(roomID string) bool {
|
func (r *SyncRequest) IsRoomPresent(roomID string) bool {
|
||||||
|
|
Loading…
Reference in a new issue