Skip to content
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

fix: Make sure we close the device proxy if node process gets killed #1153

Merged
merged 31 commits into from
Feb 12, 2020

Conversation

mykola-mokhnach
Copy link
Contributor

No description provided.

Copy link
Contributor

@imurchie imurchie left a comment

Choose a reason for hiding this comment

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

Approach seems sound. A couple of comments.

lib/device-connections-factory.js Show resolved Hide resolved
this.localServer.on('error', (e) => this.log.warn(e.message));

this.onBeforeProcessExit = () => {
if (this.localServer?.listening) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure that the dependency is set to require at least appium-gulp-plugins@5.1.0 or this won't build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@mykola-mokhnach
Copy link
Contributor Author

@KazuCocoa Could you please help debugging this code?
Is the connection closed properly for you if Appium process gets terminated with SIGINT?

@KazuCocoa
Copy link
Member

Okay, will take a look

@KazuCocoa
Copy link
Member

https://gist.github.com/KazuCocoa/18be61e5a0860eea24760cd4d5158edb

I checked as:

  1. launch appium and establish a real device session
  2. Send SIGINT to the process (Then, Appium prints Received SIGINT - shutting down)
  3. observe the behaviour...

After is this PR. Before is the current master. Exactly The connection to ... has been closed printed as same as before. Is this expected?
(Or should we close Appium immediately before the base driver timeout error and this immediate process close would like to do? )

@mykola-mokhnach
Copy link
Contributor Author

thanks @KazuCocoa
is the same behaviour observed on SIGTERM?

@mykola-mokhnach
Copy link
Contributor Author

mykola-mokhnach commented Feb 4, 2020

@KazuCocoa Would you mind checking appium/appium#13913 instead?

@KazuCocoa
Copy link
Member

is the same behaviour observed on SIGTERM?

The case was the same as SIGINT

@KazuCocoa
Copy link
Member

@mykola-mokhnach
Copy link
Contributor Author

Thanks @KazuCocoa
I've changed the code to actually wait until the server is closed. Could you please check it one more time (also including normal session deletion for a real device)?

@KazuCocoa
Copy link
Member

KazuCocoa commented Feb 5, 2020

After eae7a59 , driver.quit did not close the listening port, *:xprint-server.
Then, below error happened after .quit and started the same port again.

Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command. Original error: The port #8100 is occupied by an other process. You can either quit that process or select another free port.

The behaviour of SIGINT seemed the same. <= this case also kept the *:xprint-server listen


note:
I found appium/appium-ios-device@695da4c#r37127278 (not in this issue)

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.

7e17810 bursted CLOSE_WAIT like https://gist.github.com/KazuCocoa/8a7340f01659ee835d9da19c29fef1aa
(and never the connection succeeded)

@mykola-mokhnach
Copy link
Contributor Author

Thanks for checking that @KazuCocoa
Perhaps, you have some ideas on have to make the close server event to not wait for so long? Feel free to add commits to this PR.

@KazuCocoa
Copy link
Member

Okay. Let me take a look further

@KazuCocoa
Copy link
Member

note: Current log did not have [iProxy@242bfcc9]. So, probably TCP *:xprint-server (LISTEN) remained after quit or SIGINT as #1153 (comment)

[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 'a8d7ebea-fd2e-489d-9656-ee63d8b71142' from our master session list
[DevCon Factory] Releasing connections for 242bfcc998fd156df0bd0ad1dde8ab8e0a032114 device on any port number
[DevCon Factory] Found cached connections to release: ["242bfcc998fd156df0bd0ad1dde8ab8e0a032114:8100"]
[DevCon Factory] Releasing the listener for '242bfcc998fd156df0bd0ad1dde8ab8e0a032114:8100'
[iProxy@242bfcc9] The connection to 242bfcc998fd156df0bd0ad1dde8ab8e0a032114 has been closed
[debug] [DevCon Factory] Cached connections count: 0
[debug] [XCUITest] Not clearing log files. Use `clearSystemFiles` capability to turn on.
[iProxy@242bfcc9] The connection to 242bfcc998fd156df0bd0ad1dde8ab8e0a032114 has been closed
[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 '500de349-36b9-4762-90a3-c9d5cadb7fdb' from our master session list
[DevCon Factory] Releasing connections for 242bfcc998fd156df0bd0ad1dde8ab8e0a032114 device on any port number
[DevCon Factory] Found cached connections to release: ["242bfcc998fd156df0bd0ad1dde8ab8e0a032114:8100"]
[DevCon Factory] Releasing the listener for '242bfcc998fd156df0bd0ad1dde8ab8e0a032114:8100'
[debug] [DevCon Factory] Cached connections count: 0
[debug] [XCUITest] Not clearing log files. Use `clearSystemFiles` capability to turn on.

@@ -137,7 +137,7 @@ class DeviceConnectionsFactory {
promises.push((async () => {
log.info(`Releasing the listener for '${key}'`);
try {
await this._connectionsMapping[key].iproxy.quit();
Copy link
Member

Choose a reason for hiding this comment

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

if (e) {
reject(e);
} else {
this.log.info(`The connection to ${this.udid} has been successfully closed`);
Copy link
Member

Choose a reason for hiding this comment

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

This else never called, and timeout error happened

@KazuCocoa
Copy link
Member

After SIGINT/quit, node 6810 kazu 26u IPv6 0xa419ae1568d349f3 0t0 TCP *:xprint-server (LISTEN) has gone. Appium can establish the same port.
node 6810 kazu 28u IPv4 0xa419ae1569beb233 0t0 TCP localhost:57030->localhost:xprint-server (ESTABLISHED) also has gone after waiting a couple of seconds after SIGINT/quit.


Current implementation worked on my local for SIGING/quit and establish a new session against the same port after it.
@mykola-mokhnach

@mykola-mokhnach
Copy link
Contributor Author

Current implementation worked on my local for SIGING/quit and establish a new session against the same port after it.

This is great news @KazuCocoa !
Many thanks for your assistance. Lets merge the PR then.

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.

Thanks for the cleanup/optimisation after my change!
The latest commit works well :) LGTM (should wait for CI tho)

@mykola-mokhnach mykola-mokhnach merged commit f1b602f into appium:master Feb 12, 2020
@mykola-mokhnach mykola-mokhnach deleted the socket_free branch February 12, 2020 20:26
khanayan123 pushed a commit to khanayan123/appium-xcuitest-driver that referenced this pull request May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants