Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash trying to create UIButton on background thread #97

Closed
lilyball opened this issue Nov 19, 2016 · 9 comments
Closed

Crash trying to create UIButton on background thread #97

lilyball opened this issue Nov 19, 2016 · 9 comments

Comments

@lilyball
Copy link

We have a crash that occurs on a background thread where the backtrace is Appboy trying to set up a UI off the main thread. The stack trace looks like

Crashed: NSOperationQueue 0x17023b2e0 :: NSOperation 0x17405e150 (QOS: DEFAULT)
0  libobjc.A.dylib                0x18d93af28 objc_msgSend + 8
1  CoreFoundation                 0x18edd442c -[__NSSetM addObject:] + 332
2  UIKit                          0x194d42480 UIViewDidSetNeedsDisplay + 100
3  UIKit                          0x194d429a4 -[UILabel _setFont:] + 604
4  UIKit                          0x194dfab70 -[UIButtonLabel setFont:] + 220
5  Appboy_iOS_SDK                 0x101000b34 -[ABKInAppMessageButton setUp] (ABKInAppMessageButton.m:44)
6  Appboy_iOS_SDK                 0x101000848 -[ABKInAppMessageButton initWithFrame:] (ABKInAppMessageButton.m:24)
7  Appboy_iOS_SDK                 0x1010008c8 -[ABKInAppMessageButton init] (ABKInAppMessageButton.m:28)
8  Appboy_iOS_SDK                 0x101033278 -[ABKInAppMessageImmersive setValue:forKey:] (ABKInAppMessageImmersive.m:47)
9  Foundation                     0x18f9918a8 -[NSObject(NSKeyValueCoding) setValuesForKeysWithDictionary:] + 236
10 Appboy_iOS_SDK                 0x10104f754 +[ABKInAppMessage getInAppMessageFromDictionary:] (ABKInAppMessage.m:428)
11 Appboy_iOS_SDK                 0x1010b0ab8 -[ABKInAppMessageTriggeredAction performTriggeredAction:] (ABKInAppMessageTriggeredAction.m:20)
12 Appboy_iOS_SDK                 0x101046efc __51-[ABKTriggerManager handleTriggerFromNotification:]_block_invoke (ABKTriggerManager.m:148)
13 Foundation                     0x18f9b17e4 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
14 Foundation                     0x18f8f6358 -[NSBlockOperation main] + 96
15 Foundation                     0x18f8e6954 -[__NSOperationInternal _start:] + 620
16 Foundation                     0x18f9b3b90 __NSOQSchedule_f + 228
17 libdispatch.dylib              0x18dd791c0 _dispatch_client_callout + 16
18 libdispatch.dylib              0x18dd87444 _dispatch_queue_serial_drain + 928
19 libdispatch.dylib              0x18dd7c9a8 _dispatch_queue_invoke + 652
20 libdispatch.dylib              0x18dd8938c _dispatch_root_queue_drain + 572
21 libdispatch.dylib              0x18dd890ec _dispatch_worker_thread3 + 124
22 libsystem_pthread.dylib        0x18df812c8 _pthread_wqthread + 1288
23 libsystem_pthread.dylib        0x18df80db4 start_wqthread + 4

This is with version 2.24.3.

@Wenzhi
Copy link

Wenzhi commented Nov 19, 2016

Hey @kballard,

Thanks for the report!

According to the stack trace, it seems that viewDidSetNeedsDisplay was called after the SDK set a font of an UILabel in the background thread and caused the crash, but I'm having trouble to reproduce it in our sample app.

Could you provide more information about:

  • Do you have any customization/category for UIButton/UILabel?
  • How often do you see the crash? Is the crash consistent every time a modal in-app message with button(s) is triggered?
  • Could you provide steps to reproduce the issue?

Thanks,
Wenzhi

@lilyball
Copy link
Author

We have not reproduced the crash internally, this stack trace came from Fabric. That said, UIViewDidSetNeedsDisplay is not the cause of the crash, but rather the normal behavior of modifying a view property. The cause of the crash is the fact that you're doing UI work from a background thread. The Appboy SDK is creating and modifying a UIButton from a background thread, and this all by itself is a violation of the threading requirements for UIKit. As this stack trace demonstrates, violating UIKit's threading requirements can sometimes crash. It can also sometimes cause bad behavior, and also sometimes appear to work just fine.

@Wenzhi
Copy link

Wenzhi commented Nov 23, 2016

Hey @kballard ,

I definitely agree regarding the root cause of the crash - we're working on a fix now. If you can provide any information on the number of users affected/frequency it would help us understand the urgency here.

Thanks very much for reporting this issue.
Wenzhi

@nalexn
Copy link

nalexn commented Jan 12, 2017

+1 to the issue

The app crashed for me when Appboy SDK was expected to display an in-app message with the call
[[Appboy sharedInstance].inAppMessageController displayNextInAppMessageWithDelegate:self];

@Wenzhi
Do you have an ETA for a fix? We were going to launch our first massive in-app messages campaign targeting a few thousands users, now I think we should defer it until this issue is fixed.

SDK version we're using: Appboy-iOS-SDK 2.24.5
Crash report attached

#2. Crashed: NSOperationQueue 0x146ed2af0 :: NSOperation 0x148327d10 (QOS: LEGACY)
0  libobjc.A.dylib                0x181b2db90 objc_msgSend + 16
1  UIKit                          0x18791dbdc -[UIViewAnimationState animationForLayer:forKey:forView:] + 824
2  UIKit                          0x187651740 -[UIViewAnimationState actionForLayer:forKey:forView:] + 80
3  UIKit                          0x187610c50 +[UIView(Animation) _defaultUIViewActionForLayer:forKey:] + 120
4  UIKit                          0x187debc1c -[UIView(UIKitManual) actionForLayer:forKey:] + 124
5  QuartzCore                     0x184fa1f2c -[CALayer actionForKey:] + 100
6  QuartzCore                     0x184f97400 actionForKey(CALayer*, CA::Transaction*, NSString*) + 96
7  QuartzCore                     0x184f97270 CA::Layer::begin_change(CA::Transaction*, unsigned int, objc_object*&) + 172
8  QuartzCore                     0x184f9a360 CA::Layer::setter(unsigned int, _CAValueType, void const*) + 160
9  QuartzCore                     0x184f9c314 -[CALayer setBackgroundColor:] + 48
10 UIKit                          0x18761f270 -[UIView(Internal) _setBackgroundCGColor:withSystemColorName:] + 1064
11 UIKit                          0x18761ecd8 -[UIView(Hierarchy) _setBackgroundColor:] + 176
12 ChimpChange                    0x100307da4 -[ABKInAppMessageButton setButtonBackgroundColor:] (ABKInAppMessageButton.m:149)
13 ChimpChange                    0x100306d78 -[ABKInAppMessageButton setUp] (ABKInAppMessageButton.m:46)
14 ChimpChange                    0x100306984 -[ABKInAppMessageButton initWithFrame:] (ABKInAppMessageButton.m:23)
15 ChimpChange                    0x100306a04 -[ABKInAppMessageButton init] (ABKInAppMessageButton.m:27)
16 ChimpChange                    0x100338d6c -[ABKInAppMessageImmersive setValue:forKey:] (ABKInAppMessageImmersive.m:47)
17 Foundation                     0x182e5239c -[NSObject(NSKeyValueCoding) setValuesForKeysWithDictionary:] + 236
18 ChimpChange                    0x100355e14 +[ABKInAppMessage getInAppMessageFromDictionary:] (ABKInAppMessage.m:427)
19 ChimpChange                    0x1003b630c -[ABKInAppMessageTriggeredAction performTriggeredAction:] (ABKInAppMessageTriggeredAction.m:19)
20 ChimpChange                    0x10034d448 __51-[ABKTriggerManager handleTriggerFromNotification:]_block_invoke (ABKTriggerManager.m:188)
21 Foundation                     0x182e70540 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
22 Foundation                     0x182dc2870 -[NSBlockOperation main] + 96
23 Foundation                     0x182db2e48 -[__NSOperationInternal _start:] + 604
24 Foundation                     0x182e72934 __NSOQSchedule_f + 224
25 libdispatch.dylib              0x181f0147c _dispatch_client_callout + 16
26 libdispatch.dylib              0x181f0d4c0 _dispatch_queue_drain + 864
27 libdispatch.dylib              0x181f04f80 _dispatch_queue_invoke + 464
28 libdispatch.dylib              0x181f0f390 _dispatch_root_queue_drain + 728
29 libdispatch.dylib              0x181f0f0b0 _dispatch_worker_thread3 + 112
30 libsystem_pthread.dylib        0x182119470 _pthread_wqthread + 1092
31 libsystem_pthread.dylib        0x182119020 start_wqthread + 4

@Wenzhi
Copy link

Wenzhi commented Jan 12, 2017

Hey @kballard and @nalexn,

The release with the crash fix will be deployed no later than tomorrow, if not today. I'll comment on this issue as soon as the release is out.

Thanks again for letting us know about the issue and your patience for the fix!
Wenzhi

@Wenzhi
Copy link

Wenzhi commented Jan 13, 2017

Hey @kballard and @nalexn,

We just released 2.25.0 with the fix. Please let us know if the new SDK fixes the crash. I'm going to keep the issue open until you guys confirm that the crash stops with the new SDK.

Thanks,
Wenzhi

@briancaw
Copy link
Contributor

Hi @kballard and @nalexn

Were you able to confirm that the fix solved things? Confirmation that things are working on your end would be much appreciated, and if you're having any further issues please let us know and we'll be sure to investigate ASAP.

Thanks,
Brian

@lilyball
Copy link
Author

The crash hasn't shown up since we updated to 2.25.0, so it looks like it was fixed.

@briancaw
Copy link
Contributor

briancaw commented Feb 21, 2017

Hi @kballard

That's great to hear. Thanks very much for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants