JSONEncoder.encode causes stack overflow crash (thread_chkstk_darwin) on iOS 26.3.1 only — deeply nested Codable model [closed]

1 day ago 2
ARTICLE AD BOX

My app crashes on iOS 26.3.1 (a) only (cannot reproduce on earlier versions) with the following crash type:

Crashed: com.apple.main-thread

0 libsystem_pthread.dylib thread_chkstk_darwin + 60

1 libsystem_pthread.dylib ___chkstk_darwin + 60

2 libswiftCore.dylib KeyedEncodingContainerProtocol.encodeIfPresent<A>(_:forKey:) + 272

3 Foundation <deduplicated_symbol> + 36

4 libswiftCore.dylib _KeyedEncodingContainerBox.encodeIfPresent<A, B>(_:forKey:) + 372

5 libswiftCore.dylib KeyedEncodingContainer.encodeIfPresent<A>(_:forKey:) + 76

...

27 Foundation specialized __JSONEncoder.wrapGeneric<A, B>(_:for:) + 4916

28 Foundation JSONEncoder.encode<A>(_:) + 296

The pattern repeats encodeIfPresent → encodeIfPresent multiple times before the overflow. The crash originates from a JSONEncoder.encode() call triggered from the main thread via an Alamofire response callback.

Stack trace (simplified)

Frame 34: TransferFundsVM.validateAndSubmit(data:processId:) (TransferFundsVM.swift:1112)

Frame 35: closure in TransferFundsViewModel.fetchTransfer(type:processId:) (TransferFundsVM.swift:1087)

Frame 28: JSONEncoder.encode<A>(_:) + 296 ← crash here

Frame 0: thread_chkstk_darwin ← stack overflow

Read Entire Article