status-im / status-mobile

a free (libre) open source, mobile OS for Ethereum
https://status.app
Mozilla Public License 2.0
3.88k stars 983 forks source link

Running latest develop on real iOS device crashes with 0x8badf00d #1687

Closed oskarth closed 6 years ago

oskarth commented 7 years ago

User Story

As a developer, I want to reliably run latest develop on device to develop features that require a device, such as push notifications.

Description

Type: Bug

Summary: When running the app on device, it shows splash screen then crashes.

Expected behavior

App launches after splash screen.

Actual behavior

App builds fine. Once running it crashes after splash screen. Crash logs shows reason is 0x8badf00d, which is a form of resource limit being hit. See logs section.

Reproduction

tab 2

BUILD_IDS=ios lein repl

tab 3

tab "react-native start"

replace real_device_id with your phone ID, "instrument -s devices"

real_device_udid="87a4f458ccfad6330008d02c674cbb73d4a5f997" xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Debug -destination "platform=iOS,id=${real_device_udid}" -derivedDataPath 'build' sleep 60 ios-deploy -i "${real_device_udid}" --justlaunch --bundle build/Build/Products/Debug-iphoneos/StatusIm.app


- Observe crash logs in Xcode (Window -> Devices -> Your device -> refresh -> order by time)

Same behavior when running clean script ahead of time:

git checkout develop && git pull rm -rf node_modules rm -rf $TMPDIR/react rm -rf $TMPDIR/npm watchman watch-del-all


As well as closing all apps on phone and restarting it.
### Additional Information
* Status version: latest develop
* Operating System: iOS
* Device: iPhone 6s, 10.3.3
* Xcode: 8.3.3
* Node: 8.2.1
* OSX: 10.12.6
* react-native-cli: 2.0.1
* react-native: 0.43.4

It has worked in the past, but intermittently. Talking to other devs it seems like it works for @rasom intermittently (after restarting device) and not at all for @jeluard, and presumably most other devs.

#### Logs

Crash logs:

Exception Type: EXC_CRASH (SIGKILL) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d Triggered by Thread: 0

Filtered syslog: None found

Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libsystem_kernel.dylib 0x0000000181ed7224 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x0000000181ed709c mach_msg + 72 2 CoreFoundation 0x0000000182ea8e90 CFRunLoopServiceMachPort + 192 3 CoreFoundation 0x0000000182ea6ae4 CFRunLoopRun + 1060 4 CoreFoundation 0x0000000182dd6da4 CFRunLoopRunSpecific + 424 5 Foundation 0x00000001838f0d74 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304 6 Foundation 0x0000000183911b44 -[NSRunLoop(NSRunLoop) runUntilDate:] + 96 7 StatusIm 0x0000000100110084 +[SplashScreen show] (SplashScreen.m:19) 8 StatusIm 0x00000001000ede6c -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:49) 9 UIKit 0x000000018909d204 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 380 10 UIKit 0x00000001892a9738 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452 11 UIKit 0x00000001892af1e0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 12 UIKit 0x00000001892c3d18 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3151 + 48 13 UIKit 0x00000001892ac474 -[UIApplication workspaceDidEndTransaction:] + 168 14 FrontBoardServices 0x0000000184aa3884 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 36 15 FrontBoardServices 0x0000000184aa36f0 -[FBSSerialQueue _performNext] + 176 16 FrontBoardServices 0x0000000184aa3aa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 17 CoreFoundation 0x0000000182ea942c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24 18 CoreFoundation 0x0000000182ea8d9c CFRunLoopDoSources0 + 540 19 CoreFoundation 0x0000000182ea69a8 CFRunLoopRun + 744 20 CoreFoundation 0x0000000182dd6da4 CFRunLoopRunSpecific + 424 21 UIKit 0x0000000189096384 -[UIApplication _run] + 652 22 UIKit 0x0000000189091058 UIApplicationMain + 208 23 StatusIm 0x00000001000ee03c main (main.m:16) 24 libdyld.dylib 0x0000000181de559c start + 4 ...


Full log: https://gist.github.com/oskarth/9be2d59c19149089649b757442193a1e
oskarth commented 7 years ago

Possibly related to https://github.com/status-im/status-go/issues/273

oskarth commented 6 years ago

Slightly different stack trace this crash, notice the sync network request with package manager. As far as I can tell the only difference is that I selected "Wait for executable to be launched" under Edit Schema -> Run in Xcode, and that I'm connected to a hotspot hosted by my phone.

Date/Time:           2017-08-30 17:11:24.5001 +0200
Launch Time:         2017-08-30 17:11:04.4305 +0200
OS Version:          iPhone OS 10.3.3 (14G60)
Report Version:      104

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x000000018be0b260 semaphore_wait_trap + 8
1   libdispatch.dylib               0x000000018bcf95e8 _os_semaphore_wait + 24
2   libdispatch.dylib               0x000000018bcf8ca0 _dispatch_semaphore_wait_slow + 140
3   CFNetwork                       0x000000018d4ebcec CFURLConnectionSendSynchronousRequest + 284
4   CFNetwork                       0x000000018d5182a4 +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 120
5   StatusIm                        0x0000000100b30538 -[RCTBundleURLProvider isPackagerRunning:] (RCTBundleURLProvider.m:76)
6   StatusIm                        0x0000000100b307e8 -[RCTBundleURLProvider guessPackagerHost] (RCTBundleURLProvider.m:92)
7   StatusIm                        0x0000000100b309f8 -[RCTBundleURLProvider packagerServerHost] (RCTBundleURLProvider.m:106)
8   StatusIm                        0x0000000100b30bbc -[RCTBundleURLProvider jsBundleURLForBundleRoot:fallbackResource:] (RCTBundleURLProvider.m:123)
9   StatusIm                        0x000000010002cac4 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:29)
10  UIKit                           0x0000000192fd1e48 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 380
11  UIKit                           0x00000001931de37c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452
12  UIKit                           0x00000001931e3e24 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684
13  UIKit                           0x00000001931f88b0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3147 + 48
14  UIKit                           0x00000001931e10b8 -[UIApplication workspaceDidEndTransaction:] + 168
15  FrontBoardServices              0x000000018e9d8884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
16  FrontBoardServices              0x000000018e9d86f0 -[FBSSerialQueue _performNext] + 176
17  FrontBoardServices              0x000000018e9d8aa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
18  CoreFoundation                  0x000000018cddd42c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
19  CoreFoundation                  0x000000018cddcd9c __CFRunLoopDoSources0 + 540
20  CoreFoundation                  0x000000018cdda9a8 __CFRunLoopRun + 744
21  CoreFoundation                  0x000000018cd0ada4 CFRunLoopRunSpecific + 424
22  UIKit                           0x0000000192fcafc8 -[UIApplication _run] + 652
23  UIKit                           0x0000000192fc5c9c UIApplicationMain + 208
24  StatusIm                        0x000000010002d38c main (main.m:16)
25  libdyld.dylib                   0x000000018bd1959c start + 4

Related https://github.com/facebook/react-native/issues/10187

retro commented 6 years ago

The app is still crashing in my case. It is the same problem as before. The app runs for ~30 seconds and then crashes. I'm using run-ios.sh script made by @rasom to actually build and run the app on the iPhone. Is there a different method I could try?

Here's the log: ``` DEBUG[08-31|19:16:31] Inserted new header number=1095622 hash=ffd4ad…a0db94 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095623 hash=627f58…88c939 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095624 hash=18198e…a70ec0 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095625 hash=4d28ed…cec6ce caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095626 hash=bec0a3…b57c1f caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095627 hash=a4892f…f1c7c2 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095628 hash=a402ba…823e60 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095629 hash=29e0b3…764063 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095630 hash=3137f9…1c51b4 caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 DEBUG[08-31|19:16:31] Inserted new header number=1095631 hash=f7cd6b…37767d caller=lightchain.go:374 fn=github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/light.(*LightChain).InsertHeaderChain.func2 2017-08-31 22:16:39.117 xcodebuild[20461:220136] IDETestOperationsObserverDebug: Writing diagnostic log for test session to: /Users/retro/Projects/status-react/ios/DerivedData/StatusIm/Logs/Test/12E0CFF5-3A81-46F4-978C-66948D8CDCF3/Session-StatusImTests-2017-08-31_221639-rBV9j1.log 2017-08-31 22:16:39.118 xcodebuild[20461:205063] [MT] IDETestOperationsObserverDebug: (9275FA5D-4804-48DA-B3A2-02B5D317E9B2) Beginning test session StatusImTests-9275FA5D-4804-48DA-B3A2-02B5D317E9B2 at 2017-08-31 22:16:39.117 with Xcode 8E3004b on target { deviceSerialNumber: XXXXXXXXXXXXXX identifier: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX deviceClass: iPhone deviceName: iPhone deviceIdentifier: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX productVersion: 10.3.3 buildVersion: 14G60 deviceSoftwareVersion: 10.3.3 (14G60) deviceArchitecture: arm64 deviceTotalCapacity: 124327854080 deviceAvailableCapacity: 26865057792 deviceIsTransient: NO ignored: NO deviceIsBusy: NO deviceIsActivated: YES deviceActivationState: Activated isPasscodeLocked: NO deviceType: supportedDeviceFamilies: ( 1 ) applications: {( : Status (/private/var/containers/Bundle/Application/B7676738-D289-4C49-B585-3D8A39D25B4C/StatusIm.app) )} provisioningProfiles: {( // Removed )} activityProgress: -2 activityTitle: hasInternalSupport: NO isSupportedOS: YES developerDiskMountError: (null) (null) bootArgs: } (10.3.3 (14G60)) MDMCreateDeltaDirectory:1920 calling MDMDirectoryDiff with: state->old_bundle: /var/folders/vw/l9zr121d06gcz6ttm9wrxg7c0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/d0f087fe2b2b2c7f09d05d696cee2a39/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/StatusIm.app state->new_bundle: /Users/retro/Projects/status-react/ios/Build/Products/Debug-iphoneos/StatusIm.app state->dst_bundle: /var/folders/vw/l9zr121d06gcz6ttm9wrxg7c0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/StatusIm.app.DaazKa/StatusIm.app_sparse.ipa/Payload//StatusIm.app, binaryDiff flag: FALSE dst_ipa: /var/folders/vw/l9zr121d06gcz6ttm9wrxg7c0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/StatusIm.app.DaazKa/StatusIm.app_sparse.ipa __MDMDirectoryDiff_block_invoke.37:1473 calling writeDictToFile with: /var/folders/vw/l9zr121d06gcz6ttm9wrxg7c0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/StatusIm.app.DaazKa/StatusIm.app_sparse.ipa/ManifestCache.plist writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/vw/l9zr121d06gcz6ttm9wrxg7c0000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/StatusIm.app.DaazKa/StatusIm.app_sparse.ipa/ManifestCache.plist 2017-08-31 22:16:46.467 xcodebuild[20461:205063] Error Domain=IDETestOperationsObserverErrorDomain Code=6 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted} Testing failed: Run test suite StatusImTests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted) Failing tests: -[StatusImTests testRendersWelcomeScreen] ** TEST FAILED ** ```
oskarth commented 6 years ago

@retro Can you try the following:

You should be able to see crash logs relevant to this error under Xcode -> Window -> Devices -> Pick device crash log, refresh and sort by latest. This is where the 0x8badf00d shows up, the error you've got seems to happen before and be related to iOS tests (I've had that too FWIW, probably separate issue).

EDIT: Moving discussion about this specific PR to https://github.com/status-im/status-react/pull/1716#issuecomment-326558714

oskarth commented 6 years ago

Some more findings. Using @rasom's ./run-ios.sh real script (xcode CLI build) and multiple ios-deploy runs on either a "stale" (apps running, been on for a while) device or a "fresh" (restarted and no apps running) gives the following logs. This is without the patch applied and running on same WiFi.

Full logs: https://gist.github.com/oskarth/9620c48fba052a91dc0f4290ddeecdd2

Notice how the stale device only gets to Requiring: bignumber.js whereas the fresh one gets to Requiring: ./resources/images/contacts/FirstBlood.png

This might require running the last line in run-ios.sh multiple times: ios-deploy -i "${real_device_udid}" --justlaunch --bundle build/Build/Products/Debug-iphoneos/StatusIm.app

This slow bundling with 30s timeout would explain why it works sometimes for @rasom but not for most other people. It might be a CPU issue but also a network or memory issue. If we could figure out how to speed this part up we'd solve the issue.

Reason for multiple ios-deploy - it seems if it takes a while for it to connect. After first one, despite sleep, the packager kicks in and starts chewing slowly: Bundlingindex.ios.js▓▓▓▓▓▓▓░░░░░░░░░ 46.4% (427/627)

oskarth commented 6 years ago

Another workaround that seems to work is to do a release build and deploy it directly onto the device:

xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Release -destination "platform=iOS,id=${real_device_udid}" -derivedDataPath 'build'
ios-deploy -i "${real_device_udid}" --justlaunch  --bundle build/Build/Products/Release-iphoneos/StatusIm.app

However, this doesn't seem to give access to normal logs.

oskarth commented 6 years ago

Here's something kind of interesting: before app has finished loading, between react-native and js-dependencies dependencies are being loaded, there's a bunch of TCP calls being made. This despite the fact that iOS installation happens over USB (--no-wifi flag to ios-deploy). Anyone got any ideas what that could be about? It'd be pretty bad if we blocked on some network call before app finished loading. @rasom?

oskarth commented 6 years ago

Found another way that interestingly works:

This launches app fairly quickly. It seems to suppress logs though, as can be seen in logs.

Logs: https://gist.github.com/oskarth/5849f65196abe4d9fca6cc6eee1bb9fe

oskarth commented 6 years ago

With https://github.com/status-im/status-go/issues/273 it seems as if debug mode works. This means the watchdog doesn't kick in and the app is allowed to keep running. I'm not sure this is the end of our problems (getting a mysterious "ReferenceError: localStorage is not defined" error), but at least the app can start in debug mode with this and 0x8badf00d isn't triggered. It just takes a very long time. The root cause - slow/bad bundling and a lot of sync network traffic remains. Steps:

# Build status-go for device using that branch, see status-go README

# Replace Statusframework with your local build
(cd .. && rm -r status-react/modules/react-native-status/ios/RCTStatus/Statusgo.framework && cp -R status-go/build/bin/statusgo-ios-9.3-framework/Statusgo.framework status-react/modules/react-native-status/ios/RCTStatus/)

# Build
xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Debug -destination "platform=iOS,id=${real_device_udid}" -derivedDataPath 'build'

# Deploy with debug mode (not justlaunch)
ios-deploy -i "${real_device_udid}" --debug --bundle build/Build/Products/Debug-iphoneos/StatusIm.app

If you rebuild, make sure not to call mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack as this will overwrite your local StatusFramework version.

oskarth commented 6 years ago

The fix for ERC_BAD_ACCESS is now in status-go develop and has been built as an artifact. This means we can run in debug mode without watchdog kicking in. Because status-go API has changed we need to use https://github.com/status-im/status-react/pull/1584 commits, which aren't yet in status-react develop.

The previously mentioned errors disappear when using the latest synced status-react version of status-go branch. This will work in the meantime:

# be on latest develop
git checkout develop && git pull

 # cherry pick status-go upgrade (updated commit hash: Sep 9) 
git cherry-pick 1d201b47cbc0796dbb2494d4dbc44520cb3a2680

# use fixed status-go
mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack

# run in xcode or via command line in debug mode, make sure not to use --justlaunch but debug
ios-deploy -i "${real_device_udid}" --debug  --bundle build/Build/Products/Debug-iphoneos/StatusIm.app

We still have issues with general slowness of build but this is a separate issue as we can use debug mode for develop and not hit 0x8badf00d. Will close this issue once https://github.com/status-im/status-react/pull/1584 is merged.

Pointers, ideas and notes for speedier builds in general:

oskarth commented 6 years ago

Blocked by https://github.com/status-im/status-react/pull/1584 - once that is merged this issue should be put in the merged column.

oskarth commented 6 years ago

Fixed in develop.

nrakochy commented 6 years ago

I ran into this issue today on iOS by running

react-native run-ios --udid "id#" --configuration Debug

It created the same log as OP.

As a work-around, I dropped the original didFinishLaunchingWithOptions into a delayed didFinishLaunchingWithOptionsAfterDelay.

This prevents the app crash from timeout, but I am not sure that this issue is fixed (can't find the source where I got this work-around) -


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self performSelector:@selector(didFinishLaunchingWithOptionsAfterDelay:) withObject:launchOptions afterDelay:0.001];

    return YES;
}

- (BOOL)didFinishLaunchingWithOptionsAfterDelay:(NSDictionary *)launchOptions
{
/* Insert original here */
}