React-native-track-player: EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000 in NowPlayingInfoController.set (IOS)

Created on 4 Jul 2019  路  12Comments  路  Source: react-native-kit/react-native-track-player

Configuration

Run react-native info in your project and share the content.

  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
      Memory: 4.32 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.2 - /usr/local/bin/node
      Yarn: 1.12.1 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 14, 15, 23, 25, 26, 27, 28
        Build Tools: 26.0.2, 27.0.3, 28.0.2, 28.0.3
        System Images: android-24 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.2/10E125 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.59.4 => 0.59.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1

What react-native-track-player version are you using?
1.1.4

Issue


In fabric I see crashes that look like this. I am not able to repro this locally but does happen in production.

Crashed: com.facebook.react.TrackPlayerModuleQueue
0 libswiftCore.dylib 0x2414c27ec swift_isUniquelyReferenced_nonNull_native + 10
1 AmharicRadio 0x100d08000 specialized Dictionary.subscript.setter + 2898568
2 AmharicRadio 0x100cdeb60 NowPlayingInfoController.set(keyValue:) + 2729448
3 AmharicRadio 0x100ce8cd4 AudioPlayer.updatePlaybackValues() + 2770780
4 AmharicRadio 0x100ce8e58 AudioPlayer.AVWrapper(didChangeState:) + 2771168
5 AmharicRadio 0x100d08fec AVPlayerWrapper._state.setter + 2902644
6 AmharicRadio 0x100cebe70 AVPlayerObserver.handleTimeControlStatusChange(_:) + 2783480
7 AmharicRadio 0x100ceb520 AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2781096
8 AmharicRadio 0x100ceb694 @objc AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2781468
9 Foundation 0x214344b08 NSKeyValueNotifyObserver + 288
10 Foundation 0x214346e9c NSKeyValueDidChange + 364
11 Foundation 0x2143443bc NSKeyValueDidChangeWithPerThreadPendingNotifications.llvm.9306004367141260615 + 140
12 AVFoundation 0x219802224 -[AVPlayer _runOnIvarAccessQueueOperationThatMayChangeCurrentItemWithPreflightBlock:modificationBlock:] + 672
13 AVFoundation 0x219806adc -[AVPlayer replaceCurrentItemWithPlayerItem:] + 232
14 AmharicRadio 0x100d0a174 AVPlayerWrapper.load(from:playWhenReady:) + 2907132
15 AmharicRadio 0x100ce7d90 AudioPlayer.load(item:playWhenReady:) + 2766872
16 AmharicRadio 0x100d0ed28 QueuedAudioPlayer.add(items:playWhenReady:) + 2926512
17 AmharicRadio 0x100cf617c RNTrackPlayer.add(trackDicts:before:resolve:reject:) + 2825220
18 AmharicRadio 0x100cf6898 @objc RNTrackPlayer.add(trackDicts:before:resolve:reject:) + 2827040
19 CoreFoundation 0x213900900 __invoking___ + 144
20 CoreFoundation 0x2137e24d0 -[NSInvocation invoke] + 292
21 CoreFoundation 0x2137e3104 -[NSInvocation invokeWithTarget:] + 60
22 AmharicRadio 0x1009c0b78 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 95624
23 AmharicRadio 0x100a00154 facebook::react::invokeInner(RCTBridge, RCTModuleData, unsigned int, folly::dynamic const&) + 355172
24 AmharicRadio 0x1009ffeb4 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 354500
25 libdispatch.dylib 0x213338a38 _dispatch_call_block_and_release + 24
26 libdispatch.dylib 0x2133397d4 _dispatch_client_callout + 16
27 libdispatch.dylib 0x2132e2320 _dispatch_lane_serial_drain$VARIANT$mp + 592
28 libdispatch.dylib 0x2132e2e3c _dispatch_lane_invoke$VARIANT$mp + 428
29 libdispatch.dylib 0x2132eb4a8 _dispatch_workloop_worker_thread + 596
30 libsystem_pthread.dylib 0x213519114 _pthread_wqthread + 304
31 libsystem_pthread.dylib 0x21351bcd4 start_wqthread + 4

Code

Show us the code you are using

iOS

Most helpful comment

I'm getting similar crashes, only on devices with iOS 13.

Crashed: com.facebook.react.TrackPlayerModuleQueue
0  libswiftCore.dylib             0x191f68b00 swift_isUniquelyReferenced_nonNull_native + 38
1  xxxxx                   0x102facb64 NowPlayingInfoController.set(keyValue:) (<compiler-generated>)
2  xxxxx                   0x102facd74 protocol witness for NowPlayingInfoControllerProtocol.set(keyValue:) in conformance NowPlayingInfoController (<compiler-generated>)
3  xxxxx                   0x102fb99ec AudioPlayer.AVWrapper(didChangeState:) + 321 (AudioPlayer.swift:321)
4  xxxxx                   0x102fcb980 AVPlayerWrapper._state.setter (<compiler-generated>)
5  xxxxx                   0x102fc9dc0 AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 114 (AVPlayerObserver.swift:114)
6  xxxxx                   0x102fc9f48 @objc AVPlayerObserver.observeValue(forKeyPath:of:change:context:) (<compiler-generated>)
7  Foundation                     0x184b1b11c NSKeyValueNotifyObserver + 292
8  ???                            0x260e730184b1d200 (Missing)
9  ???                            0x1c2b058184b1a900 (Missing)
10 ???                            0x0 (Missing)
11 ???                            0x2a69e9018e95fa00 (Missing)
12 ???                            0x5153e08102fcd000 (Missing)
13 xxxxx                   0x102fb8bb4 AudioPlayer.play() + 189 (AudioPlayer.swift:189)
14 xxxxx                   0x102fdb0f4 specialized RNTrackPlayer.play(resolve:reject:) + 439 (RNTrackPlayer.swift:439)
15 xxxxx                   0x102fd43f8 @objc RNTrackPlayer.removeUpcomingTracks(resolve:reject:) + 1823540
16 CoreFoundation                 0x18476c724 __invoking___ + 148
17 ???                            0x0 (Missing)
18 ???                            0x0 (Missing)
19 ???                            0x3762750102e2de00 (Missing)
20 xxxxx                   0x102e6bba8 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) + 104 (RCTNativeModule.mm:104)
21 xxxxx                   0x102e6b908 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 365 (Optional.h:365)
22 libdispatch.dylib              0x18440bbb0 _dispatch_call_block_and_release + 32
23 ???                            0x0 (Missing)
24 ???                            0x293a2b8184413400 (Missing)
25 ???                            0x5e38650184414000 (Missing)
26 ???                            0x71123b818441d000 (Missing)
27 ???                            0x1143ed8184472b00 (Missing)
28 ???                            0x0 (Missing)

All 12 comments

Same.
This is the biggest issue in my app now.
Sadly, I don't know how to reproduce it either.

It looks like multi-thread access to Dictionary makes this crash, but I'm not sure and not familiar with the code.


Updated.

It can be in the thread com.facebook.react.TrackPlayerModuleQueue or the thread com.apple.main-thread.

Crashed: com.facebook.react.TrackPlayerModuleQueue
0  libswiftCore.dylib             0x1d20a77ec swift_isUniquelyReferenced_nonNull_native + 10
1  Xxxxxxxxxx                     0x101841da8 specialized Dictionary.subscript.setter + 2698032
2  Xxxxxxxxxx                     0x10183becc NowPlayingInfoController.set(keyValue:) + 2673748
3  Xxxxxxxxxx                     0x10183c0b8 protocol witness for NowPlayingInfoControllerProtocol.set(keyValue:) in conformance NowPlayingInfoController + 2674240
4  Xxxxxxxxxx                     0x101847b5c AudioPlayer.AVWrapper(didChangeState:) + 2722020
5  Xxxxxxxxxx                     0x10185b33c AVPlayerWrapper._state.setter + 2801860
6  Xxxxxxxxxx                     0x101859940 AVPlayerObserver.handleTimeControlStatusChange(_:) + 2795208
7  Xxxxxxxxxx                     0x101858ff0 AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2792824
8  Xxxxxxxxxx                     0x101859164 @objc AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2793196
9  Foundation                     0x1a51efb08 NSKeyValueNotifyObserver + 288
10 Foundation                     0x1a51f1e9c NSKeyValueDidChange + 364
11 Foundation                     0x1a51ef3bc NSKeyValueDidChangeWithPerThreadPendingNotifications.llvm.9306004367141260615 + 140
12 AVFoundation                   0x1aa6b26bc -[AVPlayer setRate:withVolumeRampDuration:playImmediately:rateChangeReason:] + 784
13 AVFoundation                   0x1aa6b284c -[AVPlayer setRate:] + 60
14 Xxxxxxxxxx                     0x101846f48 AudioPlayer.play() + 2718928
15 Xxxxxxxxxx                     0x10186a5d0 specialized RNTrackPlayer.play(resolve:reject:) + 2863960
16 Xxxxxxxxxx                     0x101862794 @objc RNTrackPlayer.removeUpcomingTracks(resolve:reject:) + 2831644
17 CoreFoundation                 0x1a47ab900 __invoking___ + 144
18 CoreFoundation                 0x1a468d4d0 -[NSInvocation invoke] + 292
19 CoreFoundation                 0x1a468e104 -[NSInvocation invokeWithTarget:] + 60
20 Xxxxxxxxxx                     0x10130e2b0 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 555 (RCTModuleMethod.mm:555)
21 Xxxxxxxxxx                     0x101314d58 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) + 104 (RCTNativeModule.mm:104)
22 Xxxxxxxxxx                     0x101314ab8 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 365 (Optional.h:365)
23 libdispatch.dylib              0x1a41e3a38 _dispatch_call_block_and_release + 24
24 libdispatch.dylib              0x1a41e47d4 _dispatch_client_callout + 16
25 libdispatch.dylib              0x1a418d320 _dispatch_lane_serial_drain$VARIANT$mp + 592
26 libdispatch.dylib              0x1a418de3c _dispatch_lane_invoke$VARIANT$mp + 428
27 libdispatch.dylib              0x1a41964a8 _dispatch_workloop_worker_thread + 596
28 libsystem_pthread.dylib        0x1a43c4114 _pthread_wqthread + 304
29 libsystem_pthread.dylib        0x1a43c6cd4 start_wqthread + 4
Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x1eeb3d7ec swift_isUniquelyReferenced_nonNull_native + 10
1  Xxxxxxxxxx                     0x100d39da8 specialized Dictionary.subscript.setter + 2698032
2  Xxxxxxxxxx                     0x100d33ecc NowPlayingInfoController.set(keyValue:) + 2673748
3  Xxxxxxxxxx                     0x100d340b8 protocol witness for NowPlayingInfoControllerProtocol.set(keyValue:) in conformance NowPlayingInfoController + 2674240
4  Xxxxxxxxxx                     0x100d3f7a8 AudioPlayer.updateNowPlayingPlaybackValues() + 2721072
5  Xxxxxxxxxx                     0x100d3fac0 AudioPlayer.AVWrapper(didChangeState:) + 2721864
6  Xxxxxxxxxx                     0x100d5333c AVPlayerWrapper._state.setter + 2801860
7  Xxxxxxxxxx                     0x100d54bec AVPlayerWrapper.player(statusDidChange:) + 2808180
8  Xxxxxxxxxx                     0x100d515a4 AVPlayerObserver.handleStatusChange(_:) + 2794284
9  Xxxxxxxxxx                     0x100d50d90 AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2792216
10 Xxxxxxxxxx                     0x100d51164 @objc AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 2793196
11 Foundation                     0x1c186ea08 NSKeyValueNotifyObserver + 288
12 Foundation                     0x1c177f990 -[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:] + 204
13 Foundation                     0x1c177ec80 -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 124
14 AVFoundation                   0x1c6db4104 -[AVPlayer addObserver:forKeyPath:options:context:] + 124
15 Xxxxxxxxxx                     0x100d52334 partial apply for closure #1 in AVPlayerObserver.startObserving() + 2797756
16 Xxxxxxxxxx                     0x100d50ce0 thunk for @escaping @callee_guaranteed () -> () + 2792040
17 libdispatch.dylib              0x1c0860a38 _dispatch_call_block_and_release + 24
18 libdispatch.dylib              0x1c08617d4 _dispatch_client_callout + 16
19 libdispatch.dylib              0x1c080f008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
20 CoreFoundation                 0x1c0db432c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
21 CoreFoundation                 0x1c0daf264 __CFRunLoopRun + 1924
22 CoreFoundation                 0x1c0dae7c0 CFRunLoopRunSpecific + 436
23 GraphicsServices               0x1c2faf79c GSEventRunModal + 104
24 UIKitCore                      0x1ed72dc38 UIApplicationMain + 212
25 Xxxxxxxxxx                     0x100674fec main + 16 (main.m:16)
26 libdyld.dylib                  0x1c08728e0 start + 4

I'm getting similar crashes, only on devices with iOS 13.

Crashed: com.facebook.react.TrackPlayerModuleQueue
0  libswiftCore.dylib             0x191f68b00 swift_isUniquelyReferenced_nonNull_native + 38
1  xxxxx                   0x102facb64 NowPlayingInfoController.set(keyValue:) (<compiler-generated>)
2  xxxxx                   0x102facd74 protocol witness for NowPlayingInfoControllerProtocol.set(keyValue:) in conformance NowPlayingInfoController (<compiler-generated>)
3  xxxxx                   0x102fb99ec AudioPlayer.AVWrapper(didChangeState:) + 321 (AudioPlayer.swift:321)
4  xxxxx                   0x102fcb980 AVPlayerWrapper._state.setter (<compiler-generated>)
5  xxxxx                   0x102fc9dc0 AVPlayerObserver.observeValue(forKeyPath:of:change:context:) + 114 (AVPlayerObserver.swift:114)
6  xxxxx                   0x102fc9f48 @objc AVPlayerObserver.observeValue(forKeyPath:of:change:context:) (<compiler-generated>)
7  Foundation                     0x184b1b11c NSKeyValueNotifyObserver + 292
8  ???                            0x260e730184b1d200 (Missing)
9  ???                            0x1c2b058184b1a900 (Missing)
10 ???                            0x0 (Missing)
11 ???                            0x2a69e9018e95fa00 (Missing)
12 ???                            0x5153e08102fcd000 (Missing)
13 xxxxx                   0x102fb8bb4 AudioPlayer.play() + 189 (AudioPlayer.swift:189)
14 xxxxx                   0x102fdb0f4 specialized RNTrackPlayer.play(resolve:reject:) + 439 (RNTrackPlayer.swift:439)
15 xxxxx                   0x102fd43f8 @objc RNTrackPlayer.removeUpcomingTracks(resolve:reject:) + 1823540
16 CoreFoundation                 0x18476c724 __invoking___ + 148
17 ???                            0x0 (Missing)
18 ???                            0x0 (Missing)
19 ???                            0x3762750102e2de00 (Missing)
20 xxxxx                   0x102e6bba8 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) + 104 (RCTNativeModule.mm:104)
21 xxxxx                   0x102e6b908 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 365 (Optional.h:365)
22 libdispatch.dylib              0x18440bbb0 _dispatch_call_block_and_release + 32
23 ???                            0x0 (Missing)
24 ???                            0x293a2b8184413400 (Missing)
25 ???                            0x5e38650184414000 (Missing)
26 ???                            0x71123b818441d000 (Missing)
27 ???                            0x1143ed8184472b00 (Missing)
28 ???                            0x0 (Missing)

Just to give an update, we are able to properly reproduce this issue in our app.

It only crashes when the audio is local, not streaming. We play audio, force quit the app. After opening up the app and playing that same file again, when resuming, it crashes. Here is the code for resuming:

export const streamPlay = (mediaInfo, resuming = false) => {
  if (mediaInfo.resumeAt && !resuming) {
    const resuming = async () => {
      let state = await TrackPlayer.getState();
      if (state !== TrackPlayer.STATE_READY) {
        resuming();
      } else {
        await TrackPlayer.seekTo(mediaInfo.resumeAt);
        await TrackPlayer.play();
        return;
      }
    };
    resuming();
  } else {
    TrackPlayer.play();
  }
};

@jeffmon did you find any fix?
it happens even for remote files in my case, but mostly random, and I tried to reproduce it many times even on release mode, but still unable to get the issue. I received 3 error events with this exact stack trace and all the devices were on iOS 13.3.

@nishanBende

Using v2.0.0-rc13, the problem is still there, but happens way less frequently (It didn't crash for me at all, some users were still experiencing it, but barely). The only issue with that version is that the touchscreen controls for iOS stop working, although you can patch it pretty easily.

@jeffmon @dcvz a bit update on this issue.
Disclaimer: I am not an iOS developer, still learning, below findings can be wrong.
I found these lines in NowPlayingInfoProperty.swift file and whenever the crash occurs it occurs on NowPlayingInfoController. set in elapsedTime observer, the exclamation mark in these lines scares me.
I know given that the condition of nil it might never occur, but I am not an expert on how the observer thread works. This is purely based on a hunch. I just feel the exclamation is bad over here.
I am gonna remove them and put it in release and check if any crash occurs.

case .defaultPlaybackRate(let rate):
            return rate != nil ? NSNumber(floatLiteral: rate!) : nil

case .elapsedPlaybackTime(let time):
            return time != nil ? NSNumber(floatLiteral: time!) : nil

@Guichaguri @dcvz
More logs while debugging using Thread Sanitizer, there's a data race while accessing Dictionary in NowPlayingInfoController

Stopping playback
Adding tracks: [<RNTrackPlayer.Track: 0x7b4401a63780>]
==================
WARNING: ThreadSanitizer: Swift access race (pid=36559)
  Modifying access of Swift variable at 0x7b10004c77f8 by main thread:
    #0 $s13RNTrackPlayer24NowPlayingInfoControllerC3set8keyValueyAA0cde3KeyI0_p_tF NowPlayingInfoController.swift:41 (App:x86_64+0x1019d12d6)
    #1 $s13RNTrackPlayer24NowPlayingInfoControllerCAA0cdeF8ProtocolA2aDP3set8keyValueyAA0cde3KeyJ0_p_tFTW <compiler-generated> (App:x86_64+0x1019d1a13)
    #2 $s13RNTrackPlayer05AudioB0C27updateNowPlayingCurrentTime33_662CDEC5D4DE0EBCB105CDF85222B8C6LLyySdF AudioPlayer.swift:294 (App:x86_64+0x1019f0470)
    #3 $s13RNTrackPlayer05AudioB0C9AVWrapper6seekTo9didFinishySi_SbtF AudioPlayer.swift:353 (App:x86_64+0x1019f1718)
    #4 $s13RNTrackPlayer05AudioB0CAA23AVPlayerWrapperDelegateA2aDP9AVWrapper6seekTo9didFinishySi_SbtFTW <compiler-generated> (App:x86_64+0x1019f20cf)
    #5 $s13RNTrackPlayer15AVPlayerWrapperC4seek2toySd_tFySbcfU_ AVPlayerWrapper.swift:230 (App:x86_64+0x101a2d1d3)
    #6 $s13RNTrackPlayer15AVPlayerWrapperC4seek2toySd_tFySbcfU_TA <compiler-generated> (App:x86_64+0x101a31394)
    #7 $sSbIegy_SbIeyBy_TR <compiler-generated> (App:x86_64+0x101a2d2ec)
    #8 -[AVPlayerItem _unregisterInvokeAndReleasePendingSeekCompletionHandlerForSeekID:finished:] <null> (AVFoundation:x86_64+0xac9b7)
    #9 _dispatch_client_callout <null> (libdispatch.dylib:x86_64+0x2d47)
    #10 start <null> (libdyld.dylib:x86_64+0xc24)

  Previous modifying access of Swift variable at 0x7b10004c77f8 by thread T19:
    #0 $s13RNTrackPlayer24NowPlayingInfoControllerC3set9keyValuesySayAA0cdE8KeyValue_pG_tFyAaF_pXEfU_ NowPlayingInfoController.swift:35 (App:x86_64+0x1019d0dcc)
    #1 $s13RNTrackPlayer24NowPlayingInfoControllerC3set9keyValuesySayAA0cdE8KeyValue_pG_tFyAaF_pXEfU_TA <compiler-generated> (App:x86_64+0x1019d0e78)
    #2 $sSTsE7forEachyyy7ElementQzKXEKF <null> (libswiftCore.dylib:x86_64+0x150783)
    #3 $s13RNTrackPlayer24NowPlayingInfoControllerCAA0cdeF8ProtocolA2aDP3set9keyValuesySayAA0cdE8KeyValue_pG_tFTW <compiler-generated> (App:x86_64+0x1019d1ab3)
    #4 $s13RNTrackPlayer05AudioB0C24loadNowPlayingMetaValuesyyF AudioPlayer.swift:262 (App:x86_64+0x1019efe1c)
    #5 $s13RNTrackPlayer05AudioB0C4load4item13playWhenReadyyAA0C4Item_p_SbtKF AudioPlayer.swift:169 (App:x86_64+0x1019ee5be)
    #6 $s13RNTrackPlayer011QueuedAudioB0C4load4item13playWhenReadyyAA0D4Item_p_SbtKF QueuedAudioPlayer.swift:74 (App:x86_64+0x1019d24ca)
    #7 $s13RNTrackPlayer011QueuedAudioB0C3add5items13playWhenReadyySayAA0D4Item_pG_SbtKF QueuedAudioPlayer.swift:106 (App:x86_64+0x1019d2d34)
    #8 $s13RNTrackPlayerAAC3add10trackDicts6before7resolve6rejectySaySDySSypGG_SSSgyypSgXEyAJ_AJs5Error_pSgtXEtF RNTrackPlayer.swift:343 (App:x86_64+0x101a4d95b)
    #9 $s13RNTrackPlayerAAC3add10trackDicts6before7resolve6rejectySaySDySSypGG_SSSgyypSgXEyAJ_AJs5Error_pSgtXEtFTo <compiler-generated> (App:x86_64+0x101a4ec76)
    #10 __invoking___ <null> (CoreFoundation:x86_64+0x1441cb)
    #11 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) RCTNativeModule.mm:104 (App:x86_64+0x1007ad426)
    #12 facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const RCTNativeModule.mm:71 (App:x86_64+0x1007acc66)
    #13 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) RCTNativeModule.mm:65 (App:x86_64+0x1007acb8f)
    #14 __tsan::invoke_and_release_block(void*) <null> (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x6a89b)
    #15 _dispatch_client_callout <null> (libdispatch.dylib:x86_64+0x2d47)

  Location is heap block of size 64 at 0x7b10004c77c0 allocated by thread T28:
    #0 malloc <null> (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x4c1aa)
    #1 swift_slowAlloc <null> (libswiftCore.dylib:x86_64+0x2d2ab8)
    #2 $s13RNTrackPlayer05AudioB0C24nowPlayingInfoController013remoteCommandG0AcA03NowefG8Protocol_p_AA06RemoteiG0CtcfcfA_ AudioPlayer.swift:129 (App:x86_64+0x1019ecfc2)
    #3 $s13RNTrackPlayerAAC6player33_4F9171C209EB7771832CF351A105AA9DLLAA011QueuedAudioB0CvgAFyXEfU_ RNTrackPlayer.swift:20 (App:x86_64+0x101a6095f)
    #4 $s13RNTrackPlayerAAC6player33_4F9171C209EB7771832CF351A105AA9DLLAA011QueuedAudioB0Cvg RNTrackPlayer.swift:19 (App:x86_64+0x101a3be84)
    #5 $s13RNTrackPlayerAAC05setupB06config7resolve6rejectySDySSypG_yypSgXEySSSg_AIs5Error_pSgtXEtF RNTrackPlayer.swift:151 (App:x86_64+0x101a40f25)
    #6 $s13RNTrackPlayerAAC05setupB06config7resolve6rejectySDySSypG_yypSgXEySSSg_AIs5Error_pSgtXEtFTo <compiler-generated> (App:x86_64+0x101a49d93)
    #7 __invoking___ <null> (CoreFoundation:x86_64+0x1441cb)
    #8 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) RCTNativeModule.mm:104 (App:x86_64+0x1007ad426)
    #9 facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const RCTNativeModule.mm:71 (App:x86_64+0x1007acc66)
    #10 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) RCTNativeModule.mm:65 (App:x86_64+0x1007acb8f)
    #11 __tsan::invoke_and_release_block(void*) <null> (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x6a89b)
    #12 _dispatch_client_callout <null> (libdispatch.dylib:x86_64+0x2d47)

  Thread T19 (tid=540594, running) is a GCD worker thread

  Thread T28 (tid=541921, running) is a GCD worker thread

SUMMARY: ThreadSanitizer: Swift access race NowPlayingInfoController.swift:41 in $s13RNTrackPlayer24NowPlayingInfoControllerC3set8keyValueyAA0cde3KeyI0_p_tF
==================
Skipping to track: 967

Removing ! was not the solution, still got one crash today, but what did work was adding playerObserver.stopObserving() in AVPlayerWrapper.swift's reset method which gets called on stop().
It removed the data race warning, it might also fix the crash.
I am just not sure what's the root cause, the stopObserving is already being called inside the startObserving and startObserving gets called when the asset is loaded in the closure of loadValuesAsynchronously.
If anyone can come up with an explanation that would be better, I'll try to create a repo for reproduction.

Data Race while accessing NowPlayingInfoController's set method
Screenshot 2020-02-06 at 3 55 26 AM

try this

public func set(keyValue: NowPlayingInfoKeyValue) {
        DispatchQueue.main.async { [weak self] in
            self!._info[keyValue.getKey()] = keyValue.getValue()
            self!._infoCenter.nowPlayingInfo = self!._info
        }
    }

Did anyone test @banshiAnton's solution? @nishanBende you gave it a thumbs up - did it help prevent your crashes?

@puckey Yes, i haven't seen a single crash after adding this.
I even changed below as I was getting setRate in crash logs but it was done earlier and I think your change would be enough as set was the last function in every crash log stacktrace.

  @objc(setRate:resolver:rejecter:)
    public func setRate(rate: Float, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
        print("Setting rate to \(rate)")
        player.rate = rate
        DispatchQueue.main.async {
            self.player.rate = rate
        }
        resolve(NSNull())
    }

Fix released in 1.2.4

Was this page helpful?
0 / 5 - 0 ratings