Dictionary crashed when updating value or init(capacity:) on iOS 14

Code Block swift
0
libswiftCore.dylib
swift_slowAlloc.cold.1 + 16
1
libswiftCore.dylib
swift_slowAlloc + 208
2
libswiftCore.dylib
swift_allocObject + 52
3
libswiftCore.dylib
static _DictionaryStorage.copy(original:) + 144
arrow_right 4
<compiler-generated> - Line 4311977528
specialized _NativeDictionary.copy() + 4311977528
5
<compiler-generated> - Line 4311980408
specialized _NativeDictionary.mutatingFind(_:isUnique:) + 4311980408
6
<compiler-generated> - Line 4311980920
specialized _NativeDictionary.subscript.modify + 4311980920
7
<compiler-generated> - Line 4311980676
specialized Dictionary._Variant.subscript.modify + 4311980676
8
<compiler-generated> - Line 4311976216


Another case
Code Block swift
0
libswiftCore.dylib
swift_slowAlloc.cold.1 + 16
1
libswiftCore.dylib
swift_slowAlloc + 212
2
libswiftCore.dylib
swift_allocObject + 64
3
libswiftCore.dylib
static _DictionaryStorage.allocate(scale:age:seed:) + 216
4
libswiftCore.dylib
Dictionary.init(minimumCapacity:) + 76

It seems that  swift_coldAlloc invoke malloc to allocate memory, but malloc return an invalid pointer, I'm so confused why it happened on iOS 14 only(from FireBase)
Just crash report, no code ?

here is the code

Code Block swift
for event in events {
try outputContent?.marketMap[event.symbol]?.update(with: event)
}

here is the code

Too short to investigate what's happening...

Are you sure the dictionary is accessed from only one thread? If there are some sort of multithreading issues, that may cause crash only in some limited environment.
typically, multithreading issue always crash with EXC_BAC_ACCESS, but EXC_BREAKPOINT in this context

Another issue with no multithreading issue definitely

Code Block swift
libswiftCore.dylib
swift_slowAlloc.cold.1 + 16
1
libswiftCore.dylib
swift_slowAlloc + 208
2
libswiftCore.dylib
swift_allocObject + 52
3
libswiftCore.dylib
static _DictionaryStorage.allocate(scale:age:seed:) + 152
4
libswiftCore.dylib
Dictionary.init(minimumCapacity:) + 72

Code Block swift
    func fetchContent() -> Promise<SomeContent> {
        Service.getMarketsV2().map { markets in
            var marketMap = [String: SomeMarket].init(minimumCapacity: markets.count)
            for market in markets where !market.parentMarket.isEmpty {
                marketMap[market.symbol] = market
            }
            return SomeContent(marketMap: marketMap, markets: markets)
        }
    }

Where exactly (which line) does the crash occur ?

typically, multithreading issue always crash with EXCBACACCESS, but EXC_BREAKPOINT in this context

Typically, but not always. Multithreading issues may cause any sort of unexpected behaviors.

Another issue with no multithreading issue definitely

The code you have shown cannot be a proof that your issue is not a multithreading problem.
Especially, using Promise makes me feel that your issue is a multithreading problem.

Anyway, if you have any clues about what might be causing your issue other than multithreading, it is your decision on which possibility you put high priority.

The code you have shown cannot be a proof that your issue is not a multithreading problem.
Especially, using Promise makes me feel that your issue is a multithreading problem.

Anyway, if you have any clues about what might be causing your issue other than multithreading, it is your decision on which possibility you put high priority.

Thanks for your advice we'll inspect code more carefully

Where exactly (which line) does the crash occur ?


var marketMap = [String: SomeMarket].init(minimumCapacity: markets.count)
and
marketMap[market.symbol] = market

there are two cases occurred according to callstack from firebase,

Have you found the root cause of it? I'm experiencing a similar issue but my crash happened on String interpolation. The top frames of the crash report also is from libswiftCore.dylib and to do with memory allocation.

At first glance this looks like a straightforward out-of-memory situation.

EXC_BREAKPOINT points to a Swift runtime error, and 16 lines into the swift_slowAlloc method it calls a crash method if malloc (or one of its variants) returns a non-truthy value. (https://github.com/apple/swift/blob/aaff37ffb872117cc2697920f85d8743b26a06cc/stdlib/public/runtime/Heap.cpp#L102)

Dictionary crashed when updating value or init(capacity:) on iOS 14
 
 
Q