matrix-org / matrix-org/matrix-ios-sdk

Crash in MXAggregatedEditsUpdater -> notifyEventEditsListenersOfRoom method

Open
#1,273 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Objective-C
Stars
484
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
I updated the sdk from 0.19.8 to 0.20.7, the users got many crashes, I saw the logs, they show that happened in this method.

- (void)notifyEventEditsListenersOfRoom:(NSString*)roomId replaceEvent:(MXEvent*)replaceEvent
{
    for (MXEventEditsListener *listener in self.listeners)
    {
        if ([listener.roomId isEqualToString:roomId])
        {
            listener.notificationBlock(replaceEvent);
        }
    }
}

It seems when for loop self.listeners, someplace remove some listener to cause the crash happed.

Log is like following:

1634957202 - 2021-10-23 02:46:42 +0000
*** Collection <__NSArrayM: 0x281584000> was mutated while being enumerated.
Application: Riot
Application version: 1.0.0 (r24)
Matrix SDK version: 0.20.7
Build: 24
iPhone 14.8

Main thread: YES
(
0 CoreFoundation 0x000000019c4a793c 5BBDEA97-01D2-30D8-8123-43118E96A409 + 1161532
1 libobjc.A.dylib 0x00000001b0244480 objc_exception_throw + 56
2 CoreFoundation 0x000000019c4a72ec 5BBDEA97-01D2-30D8-8123-43118E96A409 + 1159916
3 MatrixSDK 0x0000000104669d2c -[MXAggregatedEditsUpdater notifyEventEditsListenersOfRoom:replaceEvent:] + 216
4 MatrixSDK 0x0000000104669ab8 -[MXAggregatedEditsUpdater handleReplace:] + 636
5 MatrixSDK 0x0000000104670958 __34-[MXAggregations registerListener]_block_invoke + 332
6 MatrixSDK 0x000000010485050c __39-[MXSessionEventListener addRoomToSpy:]_block_invoke + 108
7 MatrixSDK 0x00000001046da4d0 -[MXEventListener notify:direction:andCustomObject:] + 160
8 MatrixSDK 0x00000001046e2454 -[MXEventTimeline notifyListeners:direction:] + 312
9 MatrixSDK 0x00000001046e1254 -[MXEventTimeline addEvent:direction:fromStore:isRoomInitialSync:] + 728
10 MatrixSDK 0x00000001046e0060 __51-[MXEventTimeline handleJoinedRoomSync:onComplete:]_block_invoke.201 + 1100
11 MatrixSDK 0x000000010484eed0 __49-[MXSession decryptEvents:inTimeline:onComplete:]_block_invoke + 320
12 libdispatch.dylib 0x000000019c0de2b0 03AD11F9-67AE-3219-ACA3-DF0A9AF629D4 + 393904
13 libdispatch.dylib 0x000000019c0df298 03AD11F9-67AE-3219-ACA3-DF0A9AF629D4 + 397976
14 libdispatch.dylib 0x000000019c0c1430 03AD11F9-67AE-3219-ACA3-DF0A9AF629D4 + 275504
15 CoreFoundation 0x000000019c426998 5BBDEA97-01D2-30D8-8123-43118E96A409 + 633240
16 CoreFoundation 0x000000019c420df8 5BBDEA97-01D2-30D8-8123-43118E96A409 + 609784
17 CoreFoundation 0x000000019c41fed0 CFRunLoopRunSpecific + 572
18 GraphicsServices 0x00000001b2b69570 GSEventRunModal + 160
19 UIKitCore 0x000000019ed4d2d0 950536E0-E3E0-3B3B-B173-BB8D185B2352 + 11731664
20 UIKitCore 0x000000019ed5284c UIApplicationMain + 164
21 Riot 0x0000000100d4358c Riot + 1635724
22 libdyld.dylib 0x000000019c0fe140 B6D35F8F-B651-3B36-972B-14B32251C4CF + 4416
)

User-Agent: iOS
Version: 1.0.0
app_language: zh_Hans
build: 24
default_app_language: zh_Hans
device: iPhone X
device_id: YRQRZDRWSO
lazy_loading: ON
local_time: 2021-10-23 10:46:52
locale: zh-Hans-US
matrix_sdk_version: 0.20.7
olm_kit_version: 3.2.5
os: iOS 14.8
utc_time: 2021-10-23 02:46:52

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at MXAggregatedEditsUpdater's notifyEventEditsListenersOfRoom:replaceEvent: method and trace how listeners are added and removed. Reproduce a listener change during notification, then verify that edit notifications complete without the “collection was mutated while being enumerated” crash and add regression coverage if the project provides a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c
Domain
mobile-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.