forcedotcom / SalesforceMobileSDK-iOS

iOS SDK for Salesforce
Other
538 stars 421 forks source link

Crash in Unit Tests on sdkPasteboard #3111

Closed AnthonyMillerSF closed 4 years ago

AnthonyMillerSF commented 4 years ago
  1. Version of Mobile SDK Used: 8.0.0

  2. Issue found in Native App or Hybrid App: Native App

  3. OS Version: 13.2

  4. Device: iPhone 8 (Simulator)

  5. Steps to reproduce:

    • Unit tests with an app target
    • In a test create a view controller with a UISearchBar
    • Display view controller:
      let window = UIWindow.init(frame: UIScreen.main.bounds)
      window.rootViewController = controller
      window.makeKeyAndVisible()
      RunLoop.main.run(until: Date())
  6. Actual behavior: Unit tests crash with EXC_BAD_INSTRUCTION during a dispatch_once in [SFUserAccountManager sharedInstance]

  7. Expected Behavior: Should not crash

  8. Error Log:

    Thread 1 Queue : com.apple.main-thread (serial)
    #0  0x00007fff51a0b170 in _dispatch_once_wait.cold.1 ()
    #1  0x00007fff519def44 in _dispatch_once_wait ()
    #2  0x0000000104c73d89 in _dispatch_once [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/dispatch/once.h:84
    #3  0x0000000104c73d6e in +[SFUserAccountManager sharedInstance] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Security/SFUserAccountManager.m:153
    #4  0x0000000104c2ff4c in +[SFSDKEventBuilderHelper createAndStoreEvent:userAccount:className:attributes:] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Analytics/SFSDKEventBuilderHelper.m:43
    #5  0x0000000104bdf120 in -[SFManagedPreferences storeAnalyticsEvent] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Util/SFManagedPreferences.m:165
    #6  0x00007fff23b7936c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
    #7  0x00007fff23b787e5 in _CFXRegistrationPost1 ()
    #8  0x00007fff23b78551 in ___CFXNotificationPost_block_invoke ()
    #9  0x00007fff23c76873 in -[_CFXNotificationRegistrar find:object:observer:enumerator:] ()
    #10 0x00007fff23b77ea6 in _CFXNotificationPost ()
    #11 0x00007fff2572bc07 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
    #12 0x0000000104c73e59 in __38+[SFUserAccountManager sharedInstance]_block_invoke.155 at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Security/SFUserAccountManager.m:154
    #13 0x00007fff519de7b9 in _dispatch_client_callout ()
    #14 0x00007fff519df9e5 in _dispatch_once_callout ()
    #15 0x0000000104c73d89 in _dispatch_once [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk/usr/include/dispatch/once.h:84
    #16 0x0000000104c73d6e in +[SFUserAccountManager sharedInstance] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Security/SFUserAccountManager.m:153
    #17 0x0000000104bded0f in -[SFManagedPreferences shouldDisableExternalPasteDefinedByConnectedApp] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Util/SFManagedPreferences.m:143
    #18 0x0000000104bb152b in +[SalesforceSDKManager sdkPasteboard] at /Users/anthony.miller/Documents/repos/REDACTED/Pods/SalesforceSDKCore/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Common/SalesforceSDKManager.m:201
    #19 0x00007fff46c922b0 in +[UIPasteboard_QSExtras generalPasteboard] ()
    #20 0x00007fff47b72c3d in +[UITextInputController _pasteboardHasStrings] ()
    #21 0x00007fff47b7306b in -[UITextInputController _shouldHandleResponderAction:] ()
    #22 0x00007fff47b57634 in -[UITextField canPerformAction:withSender:] ()
    #23 0x00007fff46f2100f in -[UISearchTextField canPerformAction:withSender:] ()
    #24 0x00007fff4787d6f6 in -[UIResponder _targetCanPerformBlock:nextTargetBlock:] ()
    #25 0x00007fff4787d878 in -[UIResponder _targetForAction:sender:skipViewControllersPresentingModally:] ()
    #26 0x00007fff476540a9 in -[UIKeyboardImpl delegateSupportsImagePaste] ()
    #27 0x00007fff47653d0f in -[UIKeyboardImpl updateDelegatePasteSupport] ()
    #28 0x00007fff4765422f in -[UIKeyboardImpl flushDelayedTasks] ()
    #29 0x00007fff476283bc in __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.880 ()
    #30 0x00007fff2574c976 in __NSFireDelayedPerform ()
    #31 0x00007fff23bb2944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
    #32 0x00007fff23bb2632 in __CFRunLoopDoTimer ()
    #33 0x00007fff23bb1c8a in __CFRunLoopDoTimers ()
    #34 0x00007fff23bac9fe in __CFRunLoopRun ()
    #35 0x00007fff23babe16 in CFRunLoopRunSpecific ()
    #36 0x00007fff2574b87f in -[NSRunLoop(NSRunLoop) runMode:beforeDate:] ()
    #37 0x00007fff2574baf2 in -[NSRunLoop(NSRunLoop) runUntilDate:] ()
    #38 0x0000000105d713d7 in static DisplayHelper.displayViewController(controller:) at /Users/anthony.miller/Documents/repos/REDACTED/REDACTEDTests/SpecHelpers/DisplayHelper.swift:9
    #39 0x0000000105e67071 in closure #1 in closure #4 in SearchUnitedWayViewControllerSpec.spec() at /Users/anthony.miller/Documents/repos/REDACTED/REDACTEDTests/Controllers/Profile/Preferred UW/SearchUnitedWayViewControllerSpec.swift:47
    #40 0x0000000106827bc7 in closure #1 in ExampleHooks.appendBefore(_:) at /Users/anthony.miller/Documents/repos/REDACTED/Pods/Quick/Sources/Quick/Hooks/ExampleHooks.swift:14
    #41 0x00000001068279ef in thunk for @escaping @callee_guaranteed (@guaranteed ExampleMetadata) -> () ()
    #42 0x0000000106827c71 in thunk for @escaping @callee_guaranteed (@guaranteed ExampleMetadata) -> ()partial apply ()
    #43 0x0000000106822ebc in thunk for @escaping @callee_guaranteed (@in_guaranteed ExampleMetadata) -> (@out ()) ()
    #44 0x0000000106821fe8 in Example.run() at /Users/anthony.miller/Documents/repos/REDACTED/Pods/Quick/Sources/Quick/Example.swift:85
    #45 0x0000000106822fab in @objc Example.run() ()
    #46 0x000000010681a095 in __60+[QuickSpec addInstanceMethodForExample:classSelectorNames:]_block_invoke at /Users/anthony.miller/Documents/repos/REDACTED/Pods/Quick/Sources/QuickObjectiveC/QuickSpec.m:108
    #47 0x00007fff23c561cc in __invoking___ ()
    #48 0x00007fff23c532df in -[NSInvocation invoke] ()
    #49 0x0000000105999a21 in __24-[XCTestCase invokeTest]_block_invoke.208 ()
    #50 0x00000001059f3b49 in -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] ()
    #51 0x00000001059f3a67 in -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] ()
    #52 0x000000010599950a in __24-[XCTestCase invokeTest]_block_invoke ()
    #53 0x0000000105998fe2 in -[XCTestCase testContextPerformInScope:] ()
    #54 0x000000010599907c in -[XCTestCase invokeTest] ()
    #55 0x000000010599aded in __26-[XCTestCase performTest:]_block_invoke_2 ()
    #56 0x00000001059f3b49 in -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] ()
    #57 0x00000001059f3a67 in -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] ()
    #58 0x000000010599ad04 in __26-[XCTestCase performTest:]_block_invoke.334 ()
    #59 0x0000000105a07352 in +[XCTContext runInContextForTestCase:block:] ()
    #60 0x000000010599a473 in -[XCTestCase performTest:] ()
    #61 0x00000001059df997 in -[XCTest runTest] ()
    #62 0x0000000105994a4a in __27-[XCTestSuite performTest:]_block_invoke ()
    #63 0x0000000105994174 in -[XCTestSuite _performProtectedSectionForTest:testSection:] ()
    #64 0x0000000105994471 in -[XCTestSuite performTest:] ()
    #65 0x00000001059df997 in -[XCTest runTest] ()
    #66 0x0000000105994a4a in __27-[XCTestSuite performTest:]_block_invoke ()
    #67 0x0000000105994174 in -[XCTestSuite _performProtectedSectionForTest:testSection:] ()
    #68 0x0000000105994471 in -[XCTestSuite performTest:] ()
    #69 0x00000001059df997 in -[XCTest runTest] ()
    #70 0x0000000105994a4a in __27-[XCTestSuite performTest:]_block_invoke ()
    #71 0x0000000105994174 in -[XCTestSuite _performProtectedSectionForTest:testSection:] ()
    #72 0x0000000105994471 in -[XCTestSuite performTest:] ()
    #73 0x00000001059df997 in -[XCTest runTest] ()
    #74 0x0000000105a162fe in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke ()
    #75 0x0000000105a16401 in __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.84 ()
    #76 0x00000001059ae793 in -[XCTestObservationCenter _observeTestExecutionForBlock:] ()
    #77 0x0000000105a160bd in -[XCTTestRunSession runTestsAndReturnError:] ()
    #78 0x0000000105977fd7 in -[XCTestDriver runTestsAndReturnError:] ()
    #79 0x0000000105a035a4 in _XCTestMain ()
    #80 0x00000001036b8be7 in __RunTests_block_invoke_2 ()
    #81 0x00007fff23bb204c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
    #82 0x00007fff23bb17b8 in __CFRunLoopDoBlocks ()
    #83 0x00007fff23bac644 in __CFRunLoopRun ()
    #84 0x00007fff23babe16 in CFRunLoopRunSpecific ()
    #85 0x00007fff38438bb0 in GSEventRunModal ()
    #86 0x00007fff4784fb48 in UIApplicationMain ()
    #87 0x0000000102345ad9 in main at  REDACTED
    #88 0x00007fff51a1dc25 in start ()
    #89 0x00007fff51a1dc25 in start ()
AnthonyMillerSF commented 4 years ago

It may have something to do with this? It looks like the [SFUserAccountManager sharedInstance] is being called recursively possibly?

https://stackoverflow.com/questions/28596305/dispatch-once-dispatch-once-singleton-freezes-locks-in-objective-c https://stackoverflow.com/questions/19176219/why-am-i-getting-deadlock-with-dispatch-once

AnthonyMillerSF commented 4 years ago

This should be fixed by the PR I just created. :)

bhariharan commented 4 years ago

Fixed here.

AnthonyMillerSF commented 4 years ago

Thanks so much for merging in my PR. Any idea on when we will get an 8.0.1 patch version pushed to Cocoapods?

bhariharan commented 4 years ago

@AnthonyMillerSF We won't be pushing a patch for this. This will be a part of our next release, 8.1.0. Meanwhile, you can use the dev branch, or cherry-pick the fix on your fork.