When using Appium for test, it often results in "UiAutomator2 server probably crashed"

When using Appium for automated testing, it errors out after running for a short period of time.

My test case suite has about 600 tests that need to run for over 5 hours in both native app and webview. However, I frequently encounter the issue where the UiAutomator2 server probably crashed. The specific error message is as follows. Has anyone experienced the same problem or can offer a direction for resolution?

[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m Calling AppiumDriver.findElements() with args: ["id","android:id/icon","f6fb1197-4481-4ec9-a1e4-86714cb4801f"]
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m Waiting up to 0 ms for condition
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: 'POST /elements' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at UIA2Proxy.command (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:355:13)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at runMicrotasks (<anonymous>)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at AndroidUiautomator2Driver.helpers.doFindElementOrEls (/home/kongyang/.appium/node_modules/appium-uiautomator2-driver/lib/commands/find.js:30:10)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at doFind (/home/kongyang/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:36:17)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at wrappedCondFn (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/timeout.ts:137:14)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at spin (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:221:20)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at waitForCondition (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:238:10)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at AndroidUiautomator2Driver.implicitWaitForCondition (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/timeout.ts:139:12)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at AndroidUiautomator2Driver.findElOrEls (/home/kongyang/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:60:5)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at AndroidUiautomator2Driver.findElOrElsWithProcessing (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:60:12)
[38;5;32m[AndroidUiautomator2Driver@d9d0 (f6fb1197)][0m     at AndroidUiautomator2Driver.findElements (/home/kongyang/.nvm/versions/node/v16.20.2/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:79:12)
[38;5;0m[HTTP][0m [37m<-- POST /wd/hub/session/f6fb1197-4481-4ec9-a1e4-86714cb4801f/elements [39m[31m500[39m [90m1 ms - 2389[39m