react-native-svg: Android crash: This dynamic value has been recycled

I’m seeing this crash log on Android in production since updating to ^7.0.0. I’m not sure how to reproduce locally but it comes a svg component that is animated using native animated. However I can’t reproduce the crash reliably so there must be some kind of race condition, it happens rather rarely, ~20 instances in the past week for a few thousand users.

I noticed the implementation uses shadow nodes to save the svg data but if I understand correctly it could just be normal uithread view manager props. Shadow nodes run on a different thread so it might be what causes this race condition.

Here’s the full stacktrace if that can be useful, the interesting part is the inner exception.

JSApplicationIllegalArgumentException
Error while updating property 'stroke' of a view managed by: RNSVGRect
com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter in updateViewProp at line 95
com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter in setProperty at line 132
com.facebook.react.uimanager.ViewManagerPropertyUpdater in updateProps at line 51
com.facebook.react.uimanager.ViewManager in updateProperties at line 34
com.facebook.react.uimanager.NativeViewHierarchyManager in createView at line 269
com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation in execute at line 200
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in dispatchPendingNonBatchedOperations at line 1105
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 1076
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 29
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher in doFrame at line 134
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1 in doFrame at line 105
android.view.Choreographer$CallbackRecord in run at line 869
android.view.Choreographer in doCallbacks at line 683
android.view.Choreographer in doFrame at line 616
android.view.Choreographer$FrameDisplayEventReceiver in run at line 857
android.os.Handler in handleCallback at line 751
android.os.Handler in dispatchMessage at line 95
android.os.Looper in loop at line 154
android.app.ActivityThread in main at line 6154
java.lang.reflect.Method in invoke
com.android.internal.os.ZygoteInit$MethodAndArgsCaller in run at line 867
com.android.internal.os.ZygoteInit in main at line 757
InvocationTargetException
java.lang.reflect.Method in invoke
com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter in updateViewProp at line 83
com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter in setProperty at line 132
com.facebook.react.uimanager.ViewManagerPropertyUpdater in updateProps at line 51
com.facebook.react.uimanager.ViewManager in updateProperties at line 34
com.facebook.react.uimanager.NativeViewHierarchyManager in createView at line 269
com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation in execute at line 200
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in dispatchPendingNonBatchedOperations at line 1105
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 1076
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 29
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher in doFrame at line 134
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1 in doFrame at line 105
android.view.Choreographer$CallbackRecord in run at line 869
android.view.Choreographer in doCallbacks at line 683
android.view.Choreographer in doFrame at line 616
android.view.Choreographer$FrameDisplayEventReceiver in run at line 857
android.os.Handler in handleCallback at line 751
android.os.Handler in dispatchMessage at line 95
android.os.Looper in loop at line 154
android.app.ActivityThread in main at line 6154
java.lang.reflect.Method in invoke
com.android.internal.os.ZygoteInit$MethodAndArgsCaller in run at line 867
com.android.internal.os.ZygoteInit in main at line 757
IllegalStateException
This dynamic value has been recycled
com.facebook.react.bridge.DynamicFromMap in asString at line 78
com.horcrux.svg.RenderableShadowNode in setStroke at line 139
com.horcrux.svg.RenderableViewManager in setStroke at line 723
java.lang.reflect.Method in invoke
com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter in updateViewProp at line 83
com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter in setProperty at line 132
com.facebook.react.uimanager.ViewManagerPropertyUpdater in updateProps at line 51
com.facebook.react.uimanager.ViewManager in updateProperties at line 34
com.facebook.react.uimanager.NativeViewHierarchyManager in createView at line 269
com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation in execute at line 200
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in dispatchPendingNonBatchedOperations at line 1105
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 1076
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 29
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher in doFrame at line 134
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1 in doFrame at line 105
android.view.Choreographer$CallbackRecord in run at line 869
android.view.Choreographer in doCallbacks at line 683
android.view.Choreographer in doFrame at line 616
android.view.Choreographer$FrameDisplayEventReceiver in run at line 857
android.os.Handler in handleCallback at line 751
android.os.Handler in dispatchMessage at line 95
android.os.Looper in loop at line 154
android.app.ActivityThread in main at line 6154
java.lang.reflect.Method in invoke
com.android.internal.os.ZygoteInit$MethodAndArgsCaller in run at line 867
com.android.internal.os.ZygoteInit in main at line 757

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 56 (14 by maintainers)

Most upvoted comments

@msand Awesome, thanks! I just tested master and everything works fine.

@msand I confirm that this issue has disappeared 🎉 for those 10% including the PR on React Native (facebook/react-native#17842) I’ll push this PR on React Native side, but might I ask: why is it that other components being animated with the native driver don’t trigger this exception while react-native-svg components do?

Our biggest crash on that newest release is now:

Caused by: java.lang.NullPointerException: 
  at com.horcrux.svg.RenderableViewManager$6.setR (RenderableViewManager.java:237)

I can open a new issue for it, I don’t think it’s related

Hi guys,

Yesterday got ~1k crashes quite similar for about ~20k users on the app yesterday.

Crashes we are getting are usually:

  • This dynamic value has been recycled
  • java.lang.ClassCastException: com.facebook.react.bridge.ReadableNativeArray cannot be cast to java.lang.Double at com.facebook.react.bridge.ReadableNativeMap.getDouble(ReadableNativeMap.java:147)
  • and java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1 at android.support.v4.util.Pools$SimplePool.release(Pools.java:116) at com.facebook.react.bridge.DynamicFromMap.recycle(DynamicFromMap.java:40)

These are new bugs in our last release that included an upgrade (among other things of course) of react-native-svg from 6.5.1 to 7.3.0.

All of those bugs seem to touch the SimplePoll recycling and upon investigation I found this PR https://github.com/facebook/react-native/pull/17842 which makes the SimplePool in DynamicFromMap thread safe.

Investigating with Android Studio debugger by setting breakpoints in DynamicFromMap.create in here, I found that this method was called by 2 threads:

  • mqt_native_modules for basic RN components
  • main only for react-native-svg

I also saw that react-native-svg is using Dynamic since version 7 of the lib (https://github.com/react-native-community/react-native-svg/commit/3879c90bd8273ba8b38713b2f39d2bdfd5265665)

So it seems like the issue could be:

  • react-native-svg started using Dynamic
  • but SimplePool in DynamicFromMap is not thread safe
  • and react-native-svg uses a different thread than default RN one

I can try downgrading react-native-svg or applying the PR above and build the app with the forked React Native version to validate that.

What do you guys think? Where is react-native-svg using a different thread?