Skip to content

Commit

Permalink
Ensure the create event is present if there is no state and no snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Aug 14, 2023
1 parent 3c9ebdf commit 8c7046e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions state/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ func (a *Accumulator) ProcessRoomEvents(userID, roomID string, timeline, state [
return nil
}

// if there is no existing snapshot AND there is no state block, then timeline[0] MUST be the create event, else we
// are seemingly getting random events without being told the room state. Whine loudly in sentry about it.
// We hypothesise that these events happen when a slow server finally sends some events to the upstream HS after a
// period of downtime. _When those events were sent_ the user was in the room, but now they are not, and /sync just
// blindly chucks them down anyway.
if snapID == 0 && gjson.ParseBytes(timeline[0]).Get("type").Str != "m.room.create" {
err := fmt.Errorf(
"ProcessRoomEvents: no state block, no existing snapID, and timeline[0] isn't m.room.create, did we just get pushed random events? room=%s user=%s len(timeline)=%d",
roomID, userID, len(timeline),
)
sentry.CaptureException(err)
return err
}

// Insert the event JSON
eventIDToNID, err := a.eventsTable.Insert(txn, dedupedEvents, false)
if err != nil {
Expand Down

0 comments on commit 8c7046e

Please sign in to comment.