Skip to content

[🐛 Bug]: [java] ExternalProcess.waitFor blocks up to 10s on driver.quit() when output-forwarder worker can't reach EOF #18209

Closed

Description

@baflQA

Description

What happened?

driver.quit() can block for ~10 seconds even though the chromedriver process itself terminates almost immediately.

The stall is in ExternalProcess.waitFor(Duration). The child process exits, so process.waitFor(...) returns true, but the output-forwarder worker thread is still blocked in InputStream.transferTo reading chromedriver's merged stdout/stderr pipe. The pipe never reaches EOF, so:

// selenium-os ExternalProcess.waitFor(Duration)
worker.join(8000);   // 8s timeout
...
worker.interrupt();
worker.join(2000);   // +2s timeout

burns the full 8000 + 2000 = 10000ms before giving up.

Thread dump evidence

Main thread parked in the second join:

at java.lang.Thread.join(Thread.java:1881)
at org.openqa.selenium.os.ExternalProcess.waitFor(ExternalProcess.java:305)
at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:309)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:575)

Output-forwarder worker, RUNNABLE, holding the pipe's ProcessPipeInputStream monitor:

"External Process Output Forwarder - .../chromedriver" #97 RUNNABLE
    at java.io.FileInputStream.readBytes(Native Method)
    at java.lang.Process$PipeInputStream.read(Process.java:1003)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:388)
    - locked <0x000000700503af40> (a java.lang.ProcessImpl$ProcessPipeInputStream)
    at java.io.InputStream.transferTo(InputStream.java:795)
    at org.openqa.selenium.os.ExternalProcess$Builder.lambda$start$0(ExternalProcess.java:219)

JDK process-reaper, BLOCKED waiting for the same monitor to finalize process exit:

"process reaper (pid 36174)" #92 BLOCKED
    at java.lang.ProcessImpl$ProcessPipeInputStream.processExited(ProcessImpl.java:610)
    - waiting to lock <0x000000700503af40> (a java.lang.ProcessImpl$ProcessPipeInputStream)

The worker holds the pipe-stream monitor inside its blocking read(); the reaper needs that monitor to run processExited() (which drains and closes the stream, i.e. the thing that would EOF the worker). They contend on the pipe write-end kept open by chrome helper/renderer child processes that inherited chromedriver's stdout fd — chromedriver exits, the children linger, so EOF is delayed until the interrupt() + join timeout forces the issue.

How can we reproduce?

Reliability is environment-sensitive — it depends on how long chrome's child processes keep the inherited stdout fd open after chromedriver exits. Seen consistently with Java 25 (25.0.4.1), Selenium 4.51.0, chromedriver 155.0.8059.84, real (headed) browser loading a heavy app (iframes, websockets, workers).

A minimal headed page quits in ~0.1–0.2s; the 10s stall shows up with a full real-world page that spawns many renderer/utility processes. It occurs once per quit(), so test suites that create a fresh driver per test pay it repeatedly.

Expected

quit() returns promptly once the process has terminated. The output-forwarder worker is a daemon reading an already-captured circular buffer; it should not be able to add ~10s to teardown. Possible directions:

  • Shorten / make configurable the worker.join timeouts in ExternalProcess.waitFor (8s + 2s is a long default).
  • interrupt() the worker before the first long join once the process has exited, rather than after.
  • Close the read side to unblock the worker once process.waitFor has returned, instead of relying on EOF.

Reproducible Code

// NOTE: the stall is timing-dependent on how long chrome's child processes keep the
// inherited stdout fd open after chromedriver exits, so a trivial page does NOT reliably
// trigger it. Harness used to observe/measure the quit() stall (watchdog dumps the
// main-thread stack mid-stall); load a heavy real page with iframes/websockets/workers:

Debugging Logs

quit() blocks ~10000ms even though the chromedriver process has already terminated.
The two thread-dump excerpts in the Description show the signature:
 - main thread parked in ExternalProcess.waitFor:305 (second worker.join)
 - "External Process Output Forwarder" worker RUNNABLE, holding the ProcessPipeInputStream monitor
 - JDK "process reaper" BLOCKED waiting for that same monitor in processExited()

Activity

  1. added
    I-defect
    A-needs-triaging
    on Oct 20, 2026
  2. selenium-ci commented on Oct 20, 2026

    @selenium-ci
    Member

    @baflQA, thank you for creating this issue. We will troubleshoot it as soon as we can.

    Selenium Triage Team: remember to follow the Triage Guide

  3. changed the title [-][🐛 Bug]: ExternalProcess.waitFor blocks up to 10s on driver.quit() when output-forwarder worker can't reach EOF (JDK 25)[/-] [+][🐛 Bug]: [java] ExternalProcess.waitFor blocks up to 10s on driver.quit() when output-forwarder worker can't reach EOF[/+] on Oct 21, 2026
  4. tediousservi commented on Oct 22, 2026

    @tediousservi
  5. tearsaalainah26 commented on Oct 22, 2026

    @tearsaalainah26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingC-javaD-chromeI-defectOS-mac

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions