Instruments Usage Error: Specified target process is invalid

Hello,

It seems as if we’re running into an intermittent issue where our execution fails within Instruments. Just as a heads up, here’s what our execution environment looks like:

Appium 1.4.16
OS: OSX
Device: iPhone 6S+ (iOS 9.1)

See below for appium logs.

e[36minfoe[39m: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
e[36minfoe[39m: Appium REST http interface listener started on 0.0.0.0:4723
e[36minfoe[39m: Console LogLevel: debug
e[36minfoe[39m: e[37m-->e[39m e[37mPOSTe[39m e[37m/wd/hub/sessione[39m e[90m{"desiredCapabilities":{"udid":"6f61dc637c95b6dad64ebce47fa956afb255bd57","platformName":"iOS","platformVersion":null,"deviceName":"iPad","sendKeyStrategy":"grouped","autoAcceptAlerts":false,"waitForAppScript":true,"app":"bundleId","newCommandTimeout":180}}e[39m
e[36minfoe[39m: Client User-Agent string: appium/ruby_lib/8.0.2
e[36minfoe[39m: [debug] App is an iOS bundle, will attempt to run as pre-existing
e[36minfoe[39m: [debug] Creating new appium session 3eb06a61-ce59-4f03-9813-4e2d55af4378
e[36minfoe[39m: [debug] Removing any remaining instruments sockets
e[36minfoe[39m: [debug] Cleaned up instruments socket /tmp/instruments_sock
e[36minfoe[39m: [debug] Auto-detecting iOS udid...
e[36minfoe[39m: [debug] Not auto-detecting udid, running on sim
e[36minfoe[39m: [debug] Could not parse plist file (as binary) at /usr/local/avm/versions/1.4.16/node_modules/appium/bundleId/en.lproj/Localizable.strings
e[36minfoe[39m: Will try to parse the plist file as XML
e[36minfoe[39m: [debug] Could not parse plist file (as XML) at /usr/local/avm/versions/1.4.16/node_modules/appium/bundleId/en.lproj/Localizable.strings
e[33mwarne[39m: Could not parse app Localizable.strings assuming it doesn't exist
e[36minfoe[39m: [debug] Creating instruments
e[36minfoe[39m: [debug] Preparing uiauto bootstrap
e[36minfoe[39m: [debug] Dynamic bootstrap dir: /Users/teamcity/Library/Application Support/appium/bootstrap
e[36minfoe[39m: [debug] Dynamic env: {"nodePath":"/usr/local/Cellar/nvm/0.29.0/versions/node/v0.12.7/bin/node","commandProxyClientPath":"/usr/local/avm/versions/1.4.16/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock","interKeyDelay":null,"justLoopInfinitely":false,"autoAcceptAlerts":false,"autoDismissAlerts":false,"sendKeyStrategy":"grouped"}
e[36minfoe[39m: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!
...
e[36minfoe[39m: [debug] Dynamic bootstrap path: /Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js
e[36minfoe[39m: [debug] Reusing dynamic bootstrap: /Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js
e[36minfoe[39m: [debug] Attempting iOS device log capture via libimobiledevice idevicesyslog
e[36minfoe[39m: [debug] Creating iDevice object with udid 6f61dc637c95b6dad64ebce47fa956afb255bd57
e[36minfoe[39m: [debug] App is installed.
e[36minfoe[39m: [debug] fullReset not requested. No need to install.
e[36minfoe[39m: [debug] Starting command proxy.
e[36minfoe[39m: [debug] Instruments socket server started at /tmp/instruments_sock
e[36minfoe[39m: [debug] Starting instruments
e[36minfoe[39m: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
e[36minfoe[39m: Launching instruments
e[36minfoe[39m: [debug] Attempting to run app on real device with UDID 6f61dc637c95b6dad64ebce47fa956afb255bd57
e[36minfoe[39m: On xcode 7.0, instruments-without-delay does not work, skippinginstruments-without-delay
e[36minfoe[39m: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6f61dc637c95b6dad64ebce47fa956afb255bd57 bundleId -e UIASCRIPT "/Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js" -e UIARESULTSPATH /tmp/appium-instruments
e[36minfoe[39m: [debug] And launch timeouts (in ms): {"global":90000}
e[36minfoe[39m: [debug] e[33m[INST STDERR] 2016-04-26 22:10:41.747 instruments[36213:4394407] WebKit Threading Violation - initial use of WebKit from a secondary thread.e[39m
e[36minfoe[39m: [debug] e[33m[INST STDERR] Instruments Usage Error: Specified target process is invalid: bundleId
instruments, version 7.3 (60133)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]e[39m
e[36minfoe[39m: [debug] e[90m[INSTSERVER] Instruments exited with code 255e[39m
e[36minfoe[39m: [debug] Killall instruments
e[36minfoe[39m: [debug] Instruments crashed on startup
e[36minfoe[39m: [debug] Attempting to retry launching instruments, this is retry #1
e[36minfoe[39m: [debug] Killall Simulator
e[36minfoe[39m: Launching instruments
e[36minfoe[39m: [debug] Attempting to run app on real device with UDID 6f61dc637c95b6dad64ebce47fa956afb255bd57
e[36minfoe[39m: On xcode 7.0, instruments-without-delay does not work, skippinginstruments-without-delay
e[36minfoe[39m: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6f61dc637c95b6dad64ebce47fa956afb255bd57 bundleId -e UIASCRIPT "/Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js" -e UIARESULTSPATH /tmp/appium-instruments
e[36minfoe[39m: [debug] And launch timeouts (in ms): {"global":90000}
e[36minfoe[39m: [debug] e[33m[INST STDERR] 2016-04-26 22:10:47.692 instruments[36242:4394622] WebKit Threading Violation - initial use of WebKit from a secondary thread.e[39m
e[36minfoe[39m: [debug] e[33m[INST STDERR] Instruments Usage Error: Specified target process is invalid: bundleId
instruments, version 7.3 (60133)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]e[39m
e[36minfoe[39m: [debug] e[90m[INSTSERVER] Instruments exited with code 255e[39m
e[36minfoe[39m: [debug] Killall instruments
e[36minfoe[39m: [debug] Instruments crashed on startup
e[36minfoe[39m: [debug] Attempting to retry launching instruments, this is retry #2
e[36minfoe[39m: [debug] Killall Simulator
e[36minfoe[39m: Launching instruments
e[36minfoe[39m: [debug] Attempting to run app on real device with UDID 6f61dc637c95b6dad64ebce47fa956afb255bd57
e[36minfoe[39m: On xcode 7.0, instruments-without-delay does not work, skippinginstruments-without-delay
e[36minfoe[39m: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6f61dc637c95b6dad64ebce47fa956afb255bd57 bundleId -e UIASCRIPT "/Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js" -e UIARESULTSPATH /tmp/appium-instruments
e[36minfoe[39m: [debug] And launch timeouts (in ms): {"global":90000}
e[36minfoe[39m: [debug] e[33m[INST STDERR] 2016-04-26 22:10:53.686 instruments[36275:4394807] WebKit Threading Violation - initial use of WebKit from a secondary thread.e[39m
e[36minfoe[39m: [debug] e[33m[INST STDERR] Instruments Usage Error: Specified target process is invalid: bundleId
instruments, version 7.3 (60133)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]e[39m
e[36minfoe[39m: [debug] e[90m[INSTSERVER] Instruments exited with code 255e[39m
e[36minfoe[39m: [debug] Killall instruments
e[36minfoe[39m: [debug] Instruments crashed on startup
e[36minfoe[39m: [debug] Attempting to retry launching instruments, this is retry #3
e[36minfoe[39m: [debug] Killall Simulator
e[36minfoe[39m: Launching instruments
e[36minfoe[39m: [debug] Attempting to run app on real device with UDID 6f61dc637c95b6dad64ebce47fa956afb255bd57
e[36minfoe[39m: On xcode 7.0, instruments-without-delay does not work, skippinginstruments-without-delay
e[36minfoe[39m: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6f61dc637c95b6dad64ebce47fa956afb255bd57 bundleId -e UIASCRIPT "/Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js" -e UIARESULTSPATH /tmp/appium-instruments
e[36minfoe[39m: [debug] And launch timeouts (in ms): {"global":90000}
e[36minfoe[39m: [debug] e[33m[INST STDERR] 2016-04-26 22:10:59.589 instruments[36284:4394900] WebKit Threading Violation - initial use of WebKit from a secondary thread.e[39m
e[36minfoe[39m: [debug] e[33m[INST STDERR] Instruments Usage Error: Specified target process is invalid: bundleId
instruments, version 7.3 (60133)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]e[39m
e[36minfoe[39m: [debug] e[90m[INSTSERVER] Instruments exited with code 255e[39m
e[36minfoe[39m: [debug] Killall instruments
e[36minfoe[39m: [debug] Instruments crashed on startup
e[36minfoe[39m: [debug] We exceeded the number of retries allowed for instruments to successfully start; failing launch
e[36minfoe[39m: [debug] Stopping iOS log capture
e[36minfoe[39m: [debug] Running ios sim reset flow
e[36minfoe[39m: [debug] Killing the simulator process
e[36minfoe[39m: [debug] Killing any other simulator daemons
e[36minfoe[39m: [debug] Killall Simulator
e[36minfoe[39m: [debug] On a real device; cannot clean device state
e[36minfoe[39m: [debug] Cleaning up appium session
e[36minfoe[39m: [debug] Error: Instruments crashed on startup
    at [object Object].Instruments.onInstrumentsExit (/usr/local/avm/versions/1.4.16/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:448:31)
    at [object Object].<anonymous> (/usr/local/avm/versions/1.4.16/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:355:12)
    at ChildProcess.emit (events.js:110:17)
    at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
e[36minfoe[39m: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}
e[36minfoe[39m: e[37m<-- POST /wd/hub/session e[39me[31m500e[39me[90m 25353.576 ms - 182e[39m e[90me[39m

When we encounter this issue, it will be consistent for every execution but can be worked around if the physical device is restarted. Tests will then successfully run until (from what we’ve observed) the latter half of the day when the problem arises again.

If any further information is needed, let me know.

Cheers

Here is the instruments command that is failing. Could you compare that to one that passes on the same device? When I read the man page for instruments it looks like the ‘bundleId’ parameter does not have the ‘-e’ (variable) flag.

Also, could you post your capabilities?

I’ll have to search around for another device to use, but in the meantime, here are the caps as pulled from the log above:

[36minfo[39m: [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [90m{"desiredCapabilities":{"udid":"6f61dc637c95b6dad64ebce47fa956afb255bd57","platformName":"iOS","platformVersion":null,"deviceName":"iPad","sendKeyStrategy":"grouped","autoAcceptAlerts":false,"waitForAppScript":true,"app":"bundleId","newCommandTimeout":180}}[39m

I should’ve noted earlier that any reference to ‘bundleId’ is an actual bundle ID that I have scrubbed for the sake of privacy.

Could you have accidentally scrubbed the ‘-e’ off as well? Because that blows my observation right out of the water.

So I ended up doing a comparison of the logs with a successful build, and I verified that the passing build is executing the same command to spawn instruments:

Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6f61dc637c95b6dad64ebce47fa956afb255bd57 bundleId -e UIASCRIPT "/Users/teamcity/Library/Application Support/appium/bootstrap/bootstrap-d66effb3cda9df33.js" -e UIARESULTSPATH /tmp/appium-instruments

The fact that we’re seeing Instruments socket client never checked in; timing out (global) as opposed to instruments being ready to receive commands seems to be of concern.

Could you try subbing the path to the app instead of bundleId? Make it an absolute (not relative) path.

Sadly, I have had no luck with specifying an absolute path instead of a bundle ID. I suppose, though, if this was the cause of the failure, then it doesn’t really explain how this sometimes periodically passes. I’m also still trying to figure out why restarting the device temporarily resolves the issue.

Sure, that makes sense. It was a bit of a shot in the dark.

I haven’t seen this before but will look into it. Out of curiosity, what version of Xcode are you using?

I appreciate the help. Here’s the version of Xcode I’m on: 7.2 (7C68)

I’ve looked around for the ‘instruments socket client never cleaned up’ problem & there seem to be many solutions, hopefully one will work for you.

  1. It is cited on a machine that is underpowered or under a heavy load. Are there any other processes running on this machine that might be taking a lot of resources? If so, does the problem go away when you kill it/them?

  2. Restarting is cited as fixing the issue. I imagine you’ve probably tried this.

  3. Permissions problem. Try ‘DevToolsSecurity -enable’ from the command line:
    https://groups.google.com/forum/#!topic/appium-discuss/eWrNCOr4Ukw

  4. Increase the launch timeout with server flag -lt or --lauch-timeout
    http://appium.io/slate/en/v1.0.0/?java#server-flags
    Instruments never checked in

The machine that this originated on was a Bamboo agent, so essentially this was executing on an isolated environment solely meant for automation. As an addition, I’ve attempted execution of this on my personal machine, and I encounter the same error.

Yep, I’ve definitely tried this, and it works as a temporary solution at best. I haven’t identified the root of the cause, but the mentioned arises again and reoccurs until the device is restarted again – as you can imagine, this is quite tedious if we were to follow this route as our solution.

At the moment, I’ve already had my device restarted as a temporary workaround, but I’ll try these suggestions once the device is back in the problematic state.

I appreciate all the help thus far. Hopefully, a resolution can be found.

I had ran into this issue. I did try all possible combinations, but eventually found that simple phone restart helped me.

1 Like

I have a very similar problem.

I tried everithing in this forum but doesn’t help me.

Any clue?

➜  ~ /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/ios/appium-instruments/instrumentscli0.trace -w 39d39a8bf0d6635268e5997dae574c04246f5e2b com.bytearc.SafariLauncher -e UIASCRIPT "/Users/adolfocabrera/Library/Application Support/appium/bootstrap/bootstrap-1f95f319c723b673.js" -e UIARESULTSPATH /tmp/ios/appium-instruments
2016-07-12 14:49:41.348 instruments[5037:1555723] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Instruments Usage Error: Specified target process is invalid: com.bytearc.SafariLauncher
instruments, version 7.3 (60134)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]

Updated: Fixed Restarting the iPad.

This happened to me too, and a phone restart did fix it, thank you!