Check if backward extremity is create event before checking missing state

This commit is contained in:
Neil Alexander 2020-10-15 11:32:35 +01:00
parent f1bc079965
commit 76c22911b7
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -546,12 +546,16 @@ func (t *txnReq) processEventWithMissingState(ctx context.Context, e gomatrixser
// 1. Ensures that the state is deduplicated fully for each state-key tuple // 1. Ensures that the state is deduplicated fully for each state-key tuple
// 2. Ensures that we pick the latest events from both sets, in the case that // 2. Ensures that we pick the latest events from both sets, in the case that
// one of the prev_events is quite a bit older than the others // one of the prev_events is quite a bit older than the others
var resolvedState *gomatrixserverlib.RespState resolvedState := &gomatrixserverlib.RespState{}
switch len(states) { switch len(states) {
case 0: case 0:
// There are no previous states - this is an error condition! extremityIsCreate := backwardsExtremity.Type() == gomatrixserverlib.MRoomCreate && backwardsExtremity.StateKeyEquals("")
util.GetLogger(ctx).WithError(err).Errorf("Failed to lookup any state after prev_events") if !extremityIsCreate {
return fmt.Errorf("expected %d states but got %d", len(backwardsExtremity.PrevEventIDs()), len(states)) // There are no previous states and this isn't the beginning of the
// room - this is an error condition!
util.GetLogger(ctx).Errorf("Failed to lookup any state after prev_events")
return fmt.Errorf("expected %d states but got %d", len(backwardsExtremity.PrevEventIDs()), len(states))
}
case 1: case 1:
// There's only one previous state - if it's trustworthy (came from a // There's only one previous state - if it's trustworthy (came from a
// local state snapshot which will already have been through state res), // local state snapshot which will already have been through state res),