Merge pull request #136 from matrix-org/dmr/removehero-panic

Reproduce and avoid panic in RemoveHero
This commit is contained in:
David Robertson 2023-06-05 12:06:13 +01:00 committed by GitHub
commit 4bb74d0df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View File

@ -87,8 +87,9 @@ func (c *GlobalCache) LoadRooms(ctx context.Context, roomIDs ...string) map[stri
roomID := roomIDs[i]
sr := c.roomIDToMetadata[roomID]
if sr == nil {
logger.Warn().Str("room", roomID).Msg("GlobalCache.LoadRoom: no metadata for this room")
continue
logger.Warn().Str("room", roomID).Msg("GlobalCache.LoadRoom: no metadata for this room, generating stub")
c.roomIDToMetadata[roomID] = internal.NewRoomMetadata(roomID)
sr = c.roomIDToMetadata[roomID]
}
srCopy := *sr
// copy the heroes or else we may modify the same slice which would be bad :(

View File

@ -255,7 +255,7 @@ func (c *UserCache) OnRegistered(ctx context.Context, _ int64) error {
// inject space children events
if room.IsSpace() {
for childRoomID := range room.ChildSpaceRooms {
c.OnSpaceUpdate(context.Background(), room.RoomID, childRoomID, false, &EventData{
c.OnSpaceUpdate(ctx, room.RoomID, childRoomID, false, &EventData{
RoomID: room.RoomID,
EventType: "m.space.child",
StateKey: &childRoomID,

View File

@ -198,3 +198,40 @@ func TestSpacesFilterInvite(t *testing.T) {
m.MatchV3SyncOp(0, 0, []string{normalRoomID}),
)))
}
// Regression test to catch https://github.com/matrix-org/sliding-sync/issues/85
func TestAddingUnknownChildToSpace(t *testing.T) {
alice := registerNewUser(t)
bob := registerNewUser(t)
t.Log("Alice creates a space and invites Bob.")
parentID := alice.CreateRoom(t, map[string]interface{}{
"type": "m.space",
"invite": []string{bob.UserID},
})
t.Log("Bob accepts the invite.")
bob.JoinRoom(t, parentID, nil)
t.Log("Bob requests a new sliding sync.")
res := bob.SlidingSync(t, sync3.Request{
Lists: map[string]sync3.RequestList{
"bob_list": {
RoomSubscription: sync3.RoomSubscription{
TimelineLimit: 10,
},
Ranges: sync3.SliceRanges{{0, 10}},
},
},
})
t.Log("Alice creates a room and marks it as a child of the space.")
childID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
childEventID := alice.SetState(t, parentID, "m.space.child", childID, map[string]interface{}{
"via": []string{"localhost"},
})
t.Log("Bob syncs until he sees the m.space.child event in the space.")
// Before the fix, this would panic inside getInitialRoomData, resulting in a 500
res = bob.SlidingSyncUntilEventID(t, res.Pos, parentID, childEventID)
}