appium用例执行过程Error: socket hang up,导致后面用例全部失败

用例执行过程中,出现 UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up 我按照网上的搜索结果重装了build-tools版本为29,仍然解决不了。偶现问题,用例一般都能通过,偶尔出现这种问题

[debug] [W3C (71e5a6f7)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,5000,"71e5a6f7-5045-41cf-942a-9f1ca66fe5f0"]
[debug] [BaseDriver] W3C timeout argument: {"implicit":5000}}
[debug] [BaseDriver] Set implicit wait to 5000ms
[debug] [W3C (71e5a6f7)] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/timeouts 200 2 ms - 14
[HTTP] 
[HTTP] --> POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/element
[HTTP] {"using":"id","value":"com.redteamobile.domestic.redteago:id/pointsFragment"}
[debug] [W3C (71e5a6f7)] Calling AppiumDriver.findElement() with args: ["id","com.redteamobile.domestic.redteago:id/pointsFragment","71e5a6f7-5045-41cf-942a-9f1ca66fe5f0"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 5000 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8201/wd/hub/session/da5b7676-9278-482b-8327-6b9da91974f1/element] with body: {"strategy":"id","selector":"com.redteamobile.domestic.redteago:id/pointsFragment","context":"","multiple":false}
[WD Proxy] Got response with unknown status: {"code":"ECONNRESET"}
[debug] [W3C (71e5a6f7)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up
[debug] [W3C (71e5a6f7)]     at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:266:13)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.helpers.doFindElementOrEls (/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/commands/find.js:27:12)
[debug] [W3C (71e5a6f7)]     at doFind (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:36:17)
[debug] [W3C (71e5a6f7)]     at wrappedCondFn (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:151:12)
[debug] [W3C (71e5a6f7)]     at spin (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:113:20)
[debug] [W3C (71e5a6f7)]     at waitForCondition (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:129:10)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.implicitWaitForCondition (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/timeout.js:153:10)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.findElOrEls (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:60:5)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.findElOrElsWithProcessing (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:33:12)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.findElement (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:10)
[HTTP] <-- POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/element 500 13 ms - 1778
[HTTP] 
[HTTP] --> GET /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/screenshot
[HTTP] {}
[debug] [W3C (71e5a6f7)] Calling AppiumDriver.getScreenshot() with args: ["71e5a6f7-5045-41cf-942a-9f1ca66fe5f0"]
[debug] [WD Proxy] Matched '/screenshot' to command name 'getScreenshot'
[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8201/wd/hub/session/da5b7676-9278-482b-8327-6b9da91974f1/screenshot] with no body
[WD Proxy] Got response with unknown status: {"code":"ECONNRESET"}
[debug] [W3C (71e5a6f7)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up
[debug] [W3C (71e5a6f7)]     at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:266:13)
[debug] [W3C (71e5a6f7)]     at AndroidUiautomator2Driver.commands.getScreenshot (/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/commands/screenshot.js:14:10)
[HTTP] <-- GET /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/screenshot 500 11 ms - 697
[HTTP] 
[HTTP] --> POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/appium/device/start_activity
[HTTP] {"appPackage":"com.redteamobile.domestic.redteago","appActivity":"com.redteamobile.ferrari.ui.splash.SplashActivity"}
[debug] [W3C (71e5a6f7)] Calling AppiumDriver.startActivity() with args: ["com.redteamobile.domestic.redteago","com.redteamobile.ferrari.ui.splash.SplashActivity",null,null,null,null,null,null,null,null,null,"71e5a6f7-5045-41cf-942a-9f1ca66fe5f0"]
[debug] [AndroidDriver] Starting package 'com.redteamobile.domestic.redteago' and activity 'com.redteamobile.ferrari.ui.splash.SplashActivity'
[debug] [ADB] Running '/Users/zhengyiming/Library/Android/sdk/platform-tools/adb -P 5037 -s b3a757fc shell am start -W -n com.redteamobile.domestic.redteago/com.redteamobile.ferrari.ui.splash.SplashActivity -S'
^C[Appium] Received SIGINT - shutting down
[debug] [Appium] Cleaning up 1 active session
[Appium] Closing session, cause was 'The process has received SIGINT signal'
[Appium] Removing session '71e5a6f7-5045-41cf-942a-9f1ca66fe5f0' from our master session list
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [WD Proxy] Matched '/' to command name 'deleteSession'
[debug] [WD Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8201/wd/hub/session/da5b7676-9278-482b-8327-6b9da91974f1] with no body
[debug] [W3C (71e5a6f7)] Encountered internal error running command: Error: The process has received SIGINT signal
[debug] [W3C (71e5a6f7)]     at map (/usr/local/lib/node_modules/appium/lib/appium.js:501:84)
[debug] [W3C (71e5a6f7)]     at Array.map (<anonymous>)
[debug] [W3C (71e5a6f7)]     at AppiumDriver.deleteAllSessions (/usr/local/lib/node_modules/appium/lib/appium.js:501:33)
[debug] [W3C (71e5a6f7)]     at process.onSignal (/usr/local/lib/node_modules/appium/lib/main.js:148:28)
[debug] [W3C (71e5a6f7)]     at Object.onceWrapper (events.js:421:26)
[debug] [W3C (71e5a6f7)]     at process.emit (events.js:314:20)
[debug] [W3C (71e5a6f7)]     at process.emit (/usr/local/lib/node_modules/appium/node_modules/source-map-support/source-map-support.js:485:21)
[HTTP] <-- POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/appium/device/start_activity 500 409 ms - 685
[HTTP] 
[Logcat] Logcat terminated with code null, signal SIGINT
[WD Proxy] Got response with unknown status: {"code":"ECONNRESET"}
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up
[debug] [ADB] Running '/Users/zhengyiming/Library/Android/sdk/platform-tools/adb -P 5037 -s b3a757fc shell am force-stop com.redteamobile.domestic.redteago'
[HTTP] --> POST /wd/hub/session/71e5a6f7-5045-41cf-942a-9f1ca66fe5f0/element
[HTTP] {"using":"id","value":"com.redteamobile.domestic.redteago:id/pointsFragment"}
[debug] [W3C (71e5a6f7)] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started
[debug] [W3C (71e5a6f7)]     at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:255:15)
[debug] [W3C (71e5a6f7)]     at /usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:447:15
[debug] [W3C (71e5a6f7)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (71e5a6f7)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
[debug] [W3C (71e5a6f7)]     at Route.dispatch (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:112:3)
[debug] [W3C (71e5a6f7)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (71e5a6f7)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:281:22
[debug] [W3C (71e5a6f7)]     at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:354:14)
[debug] [W3C (71e5a6f7)]     at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:365:14)
[debug] [W3C (71e5a6f7)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:410:3)
[debug] [W3C (71e5a6f7)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C (71e5a6f7)]     at logger (/usr/local/lib/node_modules/appium/node_modules/morgan/index.js:144:5)
[debug] [W3C (71e5a6f7)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (71e5a6f7)]     at trim_prefix (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [W3C (71e5a6f7)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [W3C (71e5a6f7)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C (71e5a6f7)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C (71e5a6f7)]     at /usr/local/lib/node_modules/appium/node_modules/body-parser/lib/read.js:130:5
[debug] [W3C (71e5a6f7)]     at invokeCallback (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:224:16)
[debug] [W3C (71e5a6f7)]     at done (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:213:7)
[debug] [W3C (71e5a6f7)]     at IncomingMessage.onEnd (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:273:7)
[debug] [W3C (71e5a6f7)]     at IncomingMessage.emit (events.js:314:20)

不明白它为什么又新创建了一个sessionid

uiautomator2-server进程挂掉了,可能是上次自动化没调用quit导致了一分钟后才自动结束,结果影响了下次的自动化。

不是两次session,一个是appium的session,一个是底层驱动uiautomator2-server的session而已。一直都是两个session配合的。