Skip to content

fix: Explicitly wait for the server shutdown before killing it forcefully #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 20, 2025

Conversation

mykola-mokhnach
Copy link
Contributor

No description provided.

@mykola-mokhnach mykola-mokhnach requested a review from jlipps March 19, 2025 07:45
@@ -438,11 +426,35 @@ class UiAutomator2Server {
await this.adb.killProcessesByName('uiautomator');
} catch {}
}
await waitStop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I could remember is this random process end delay could occur after the adb.forceStop also because according to the device's adb log, the process kill related log itself delayed after sending a kill command. I still think we need to ensure the uia2 server has ended in cleanupAutomationLeftovers as the method's purpose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me search my past logs if the this.adb.processExists was reliable on such env. Maybe I have some research comment somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a good log if this.adb.processExists is reliable, but I think it should be ok.

So far, I observed the process kill delay in adb logcat before, so we need to assume this.adb.forceStop itself could have delay to kill the process on the OS internal level. But I assume this.adb.processExists itself should be ok instead of /status endpoint check

Copy link
Contributor Author

@mykola-mokhnach mykola-mokhnach Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for checking it.

Basically, this is what I figured out so far by analyzing the server code:

after receiving the shutdown request (which is sent as part of the DELETE session request) the server will asynchronously:

  • shutdown http listener and other side servers, like mjpeg broadcaster
  • exit the main Junit runner entry point
  • exit the server process, which would also stop the instrumentation monitoring

The previous check (GET /status) was only verifying the first stage completion, while we actually need to wait for the last one. On my test phone the time difference between the first and the last stage completion is about 400ms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this PR idea looks good. Let me see HS's device pool, which could be good for this testing purpose. The original issue was Samsung Android 13+, so probably I could find a device

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg

I couldn't find the original issue's device but did 100+ loop to start/terminate appium sessions with multiple Samsung Android13+ devices. They didn't have any weird delay issue, so probably good with this

@mykola-mokhnach mykola-mokhnach merged commit d3f50ef into appium:master Mar 20, 2025
9 checks passed
@mykola-mokhnach mykola-mokhnach deleted the sess_del branch March 20, 2025 08:19
github-actions bot pushed a commit that referenced this pull request Mar 20, 2025
## [4.1.4](v4.1.3...v4.1.4) (2025-03-20)

### Bug Fixes

* Explicitly wait for the server shutdown before killing it forcefully ([#873](#873)) ([d3f50ef](d3f50ef))
Copy link

🎉 This PR is included in version 4.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants