Skip to content

[πŸ› Bug]: ExternalProcess cannot properly handle graceful process terminationΒ #14569

@mykola-mokhnach

Description

@mykola-mokhnach

What happened?

See appium/java-client#2238 for more details.

I've tried to debug the issue locally and it looks like the main culprit lies in the default java's Process.destroy implementation:

   private void destroy(boolean force) {
        switch (OperatingSystem.current()) {
            case LINUX:
            case AIX:
            case MACOS:
                this.lock.lock();

                try {
                    if (!this.hasExited) {
                        this.processHandle.destroyProcess(force);
                    }
                } finally {
                    this.lock.unlock();
                }

                try {
                    this.stdin.close();
                } catch (IOException var9) {
                }

                try {
                    this.stdout.close();
                } catch (IOException var8) {
                }

                try {
                    this.stderr.close();
                } catch (IOException var7) {
                }

                return;
            default:
                throw new AssertionError("Unsupported platform: " + OperatingSystem.current());
        }

As you can see there after it sends the signal for process termination it also always implicitly closes all process streams, which creates EPIPE errors mentioned in the above issue and also drops several recent log lines from the Appium Node.js process log. As a fix we should not close process streams unless the next waitFor method completes or we destroy the process forcefully.

My proposed fix for this issue would be to update the implementation of org.openqa.selenium.os.ExternalProcess class -> shutdown method. Instead of

        process.destroy();

cal something like (pseudocode)

    if (isWindows) {
       run(["taskkill.exe", "/pid", process.pid]);
    } else {
       run(["kill", "-2", process.pid]);
    }

How can we reproduce the issue?

Just run the code from https://github.com/appium/java-client/issues/2238, which starts and stop Appium process. You may use the `npm i appium` command to install Appium itself.

Relevant log output

uncaughtException: write EPIPE
Error: write EPIPE

Operating System

all

Selenium version

latest

What are the browser(s) and version(s) where you see this issue?

all

What are the browser driver(s) and version(s) where you see this issue?

all

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-javaJava BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions