Rxswift: Crash in MergeBasicSink with Xcode 11.2

Created on 1 Nov 2019  路  9Comments  路  Source: ReactiveX/RxSwift

Short description of the issue:

I'm getting crashes when using merge() with Xcode 11.2. Same code with 11.1 works fine.

What actually happens:

EXC_BAD_ACCESS (code=1, address=0x0)

``* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x00007fff5132ba49 libswiftCore.dylib_swift_initClassMetadataImpl(swift::TargetClassMetadata, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const const, unsigned long, bool) + 1337
frame #1: 0x0000000106c0bc46 Testtype metadata completion function for MergeSink at <compiler-generated>:0 frame #2: 0x00007fff51332ced libswiftCore.dylibswift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry, swift::MetadataRequest) + 285
frame #3: 0x00007fff51329767 libswiftCore.dylibswift_getGenericMetadata + 1527 frame #4: 0x0000000106c0bc90 Testtype metadata accessor for MergeSink at :0
frame #5: 0x00007fff513420e1 libswiftCore.dylib(anonymous namespace)::DecodedMetadataBuilder::createBoundGenericType(swift::TargetContextDescriptor<swift::InProcess> const*, llvm::ArrayRef<swift::TargetMetadata<swift::InProcess> const*>, swift::TargetMetadata<swift::InProcess> const*) const + 257 frame #6: 0x00007fff51340e7e libswiftCore.dylibswift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node) + 3726
frame #7: 0x00007fff5133e32b libswiftCore.dylibswift_getTypeByMangledNodeImpl(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node*, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) + 411 frame #8: 0x00007fff5133e132 libswiftCore.dylibswift::swift_getTypeByMangledNode(swift::MetadataRequest, swift::Demangle::Demangler&, swift::Demangle::Node
, void const* const, std::__1::function const (unsigned int, unsigned int)>, std::__1::function const* (swift::TargetMetadata const, unsigned int)>) + 482
frame #9: 0x00007fff5133e6bb libswiftCore.dylibswift_getTypeByMangledNameImpl(swift::MetadataRequest, llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) + 779 frame #10: 0x00007fff5133c1c2 libswiftCore.dylibswift::swift_getTypeByMangledName(swift::MetadataRequest, llvm::StringRef, void const
const, std::__1::function const (unsigned int, unsigned int)>, std::__1::function const* (swift::TargetMetadata const, unsigned int)>) + 482
frame #11: 0x00007fff51330d7a libswiftCore.dylibgetSuperclassMetadata(swift::TargetClassMetadata<swift::InProcess>*, bool) + 330 frame #12: 0x00007fff5132b53b libswiftCore.dylib_swift_initClassMetadataImpl(swift::TargetClassMetadata
, swift::ClassLayoutFlags, unsigned long, swift::TypeLayout const* const, unsigned long, bool) + 43
frame #13: 0x0000000106c0b905 Testtype metadata completion function for MergeBasicSink at <compiler-generated>:0 frame #14: 0x00007fff51332ced libswiftCore.dylibswift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry, swift::MetadataRequest) + 285
frame #15: 0x00007fff51329767 libswiftCore.dylibswift_getGenericMetadata + 1527 frame #16: 0x0000000106c0b4b0 Testtype metadata accessor for MergeBasicSink at :0

  • frame #17: 0x0000000106c09e24 TestMerge.run<SourceSequence>(observer=0x0000600002b249c0, cancel=0x0000600002421260, self=0x0000600000f3cea0) at Merge.swift:580:20 frame #18: 0x0000000106c2e535 TestProducer.subscribe(observer=0x0000600002b249c0, self=0x0000600000f3cea0) at Producer.swift:18:44
    frame #19: 0x0000000106bfa690 TestMap.run<SourceType>(observer=0x000060000017a640, cancel=0x0000600002420f50, self=0x000060000017a4f0) at Map.swift:99:41 frame #20: 0x0000000106c2ee28 Testclosure #1 in Producer.subscribe(_0=() @ scalar, self=0x000060000017a4f0, observer=0x000060000017a640) at Producer.swift:26:48
    frame #21: 0x0000000106c2ef3c Testpartial apply for closure #1 in Producer.subscribe<A>(_:) at <compiler-generated>:0 frame #22: 0x0000000106bcc1cc Testthunk for @escaping @callee_guaranteed () -> (@out Disposable) at :0
    frame #23: 0x0000000106c2ef91 Testpartial apply for thunk for @escaping @callee_guaranteed () -> (@out Disposable) at <compiler-generated>:0 frame #24: 0x0000000106bb875f TestCurrentThreadScheduler.schedule(state=() @ 0xffffffffffffffff, action=0x0000000106c2ef80 Testpartial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed () -> (@out RxSwift.Disposable) to @escaping @callee_guaranteed (@in_guaranteed ()) -> (@out RxSwift.Disposable) at <compiler-generated>, self=0x0000600000d282b0) at CurrentThreadScheduler.swift:101:30 frame #25: 0x0000000106c2e714 TestProducer.subscribe(observer=0x000060000017a640, self=0x000060000017a4f0) at Producer.swift:24:52
    frame #26: 0x0000000106c1633d TestObservableType.subscribe(on=0x0000000106d122b0 Testpartial apply forwarder for closure #1 (RxSwift.Event) -> () in (extension in RxCocoa):RxSwift.ObservableType.(bind in _F14B11F29E4023218E8359F9EC4A42AD)(to: Swift.Array) -> RxSwift.Disposable at , self=0x000060000017a4f0) at ObservableType+Extensions.swift:25:40
    frame #27: 0x0000000106d11983 TestObservableType.bind<Self>(observers=1 value, self=0x000060000017a4f0) at Observable+Bind.swift:42:21 frame #28: 0x0000000106d118bd TestObservableType.bind(observers=1 value, self=0x000060000017a4f0) at Observable+Bind.swift:20:21
    frame #29: 0x0000000106b3dafc TestAppDelegate.application(application=0x00007fcb08c00080, launchOptions=nil, self=0x0000600000d08150) at AppDelegate.swift:27:6 frame #30: 0x0000000106b3e4b4 Test@objc AppDelegate.application(_:didFinishLaunchingWithOptions:) at :0
    frame #31: 0x00007fff478467a8 UIKitCore-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 232 frame #32: 0x00007fff478481b7 UIKitCore-[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3980
    frame #33: 0x00007fff4784dd06 UIKitCore-[UIApplication _runWithMainScene:transitionContext:completion:] + 1281 frame #34: 0x00007fff46f84422 UIKitCore-[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
    frame #35: 0x00007fff4784a2a6 UIKitCore-[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59 frame #36: 0x00007fff4784a5a5 UIKitCore-[UIApplication _run] + 754
    frame #37: 0x00007fff4784fb68 UIKitCoreUIApplicationMain + 1621 frame #38: 0x0000000106b3eaeb Testmain at AppDelegate.swift:14:7
    frame #39: 0x00007fff51a1dc25 libdyld.dylibstart + 1 frame #40: 0x00007fff51a1dc25 libdyld.dylibstart + 1
**Self contained code example that reproduces the issue**:

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let aBinder = Binder<String>(self) { _, str in
      print(str)
    }

    _ = Observable.of(
      NotificationCenter.default.rx.notification(UIApplication.willResignActiveNotification),
      NotificationCenter.default.rx.notification(UIApplication.didBecomeActiveNotification)
    )
    .merge()
    .map { _ in "test" }
    .bind(to: aBinder)

    return true
}

Sample project is attached: Test.zip

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

5.0.1

Platform/Environment

  • [x] iOS
  • [ ] macOS
  • [ ] tvOS
  • [ ] watchOS
  • [ ] playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • [x] easy, 100% repro
  • [ ] sometimes, 10%-100%
  • [ ] hard, 2% - 10%
  • [ ] extremely hard, %0 - 2%

Xcode version:

Version 11.2 (11B52)

Installation method:

  • [x] SPM
  • [ ] CocoaPods
  • [ ] Carthage
  • [ ] Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • [ ] yes (which ones)
  • [x] no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • [ ] just starting
  • [ ] I have a small code base
  • [x] I have a significant code base

Most helpful comment

Temporary workaround that fixes it:

-Go to Project Target/Build Settings
-"Dead Code Stripping" to NO

All 9 comments

Related to #2094

As mentioned in other issue thread 鈥撀燾aused by SR-11564. (https://bugs.swift.org/browse/SR-11564)

馃う鈥嶁檪

Usually when somebody says

Xcode 11.2. Same code with 11.1 works fine.

that means it's not our bug :)

Temporary workaround that fixes it:

-Go to Project Target/Build Settings
-"Dead Code Stripping" to NO

Confirming that setting Dead Code Stripping to NO works. Otherwise crashes happen even when compiled with Xcode 11.1 after submitting to TestFlight.

I'm not able to run XCTests on Xcode 11.1,11.2 as it crashes from debounce with Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

Screenshot 2019-11-04 at 16 24 11

Screenshot 2019-11-04 at 16 24 30

Dead Code Stripping is set to NO
Anyone else experiencing the same issue or any work around for this case? (It works in Xcode 10.3)

Seeing this issue with a very simple code sample built using Carthage

Dead Code Stripping set to No

var updateString = BehaviorRelay<String>(value: "")

@IBOutlet weak var fetchButton: UIButton!
@IBOutlet weak var outputLabel: UILabel!

@IBAction func buttonTapped(_ sender: UIButton) {
  updateString.accept("Updated")
}
override func viewDidLoad() {
  super.viewDidLoad()
  updateString.bind(to: outputLabel.rx.text).disposed(by: disposeBag)
}

Crashes me immediately while initializing the Binder

Unfortunately this is a bug with SPM. People already filed a bug and I hope it would be fixed soon, but there's nothing much we can do as a framework.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acecilia picture acecilia  路  3Comments

marlowcharite picture marlowcharite  路  3Comments

tyregor picture tyregor  路  3Comments

gaudecker picture gaudecker  路  3Comments

hannesstruss picture hannesstruss  路  3Comments