Repository navigation
[java] stop waiting for process output once it is silent - #18211
Conversation
…8209 ExternalProcess.waitFor and shutdown join the output forwarder until it reaches the end of the stream, for up to 8 + 2 seconds. A child process that inherited stdout, e.g. a browser helper started by chromedriver, keeps the stream open after the driver itself exited. The forwarder then blocks in read until both timeouts elapsed, so every driver.quit() could take about 10 seconds. The forwarder now counts the bytes it copies. After the process exited, waitFor and shutdown keep waiting while output still arrives, up to the existing 8 second cap, and stop once no output arrived for 500 ms. All output the process wrote is still read completely, which SeleniumHQ#13091 and SeleniumHQ#14820 rely on for Selenium Manager. Fixes SeleniumHQ#18209
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
/agentic_review |
Code Review by Qodo
1.
|
A write to a slow copyOutputTo stream left the forwarded byte count unchanged for longer than the quiet period, so waitFor stopped waiting while output was still being forwarded. A write in progress now counts as output. When the copy fails, e.g. after DriverService closed its log file while a child of the driver still writes, the forwarder stopped reading the pipe and the child could block on it. It now keeps reading and discards the rest.
fec4f48 to
24c128f
Compare
|
@gjreddy can You please sign the CLA? |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 24c128f |
|
@baflQA @diemol bottom note, you can see the confirmation that I signed CLA.
|
A write that ended between reading the count and reading the flag looked like silence. Reading the flag first means such a write has already advanced the count.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
@titusfortner @diemol do You have the power to make it to the trunk? |
|
Code review by qodo was updated up to the latest commit 61b46c3 |
🔗 Related Issues
Fixes #18209
What does this PR do?
ExternalProcess.waitForandshutdownno longer wait up to 10 seconds for the end of a driver's output stream when a child process keeps that stream open.After the process exits, both methods join the output forwarder until it reaches EOF, for up to
8000 + 2000ms. A browser helper started by chromedriver inherits its stdout, so the stream stays open after the driver itself exited, anddriver.quit()waits out both timeouts.🔧 Implementation Notes
waitForandshutdownshare a newawaitWorker(): after the process exited it keeps joining while output still arrives, up to the existing 8 s cap, and stops once nothing arrived for 500 ms.interrupt()is kept for the case where output is still flowing at the 8 s cap. It is skipped when the output went silent, asinterrupt()does not unblock a pipe read.ExternalProcess(Process, OutputStream, Thread)constructor has no byte count, so it keeps the old behaviour.I did not simply shorten the timeouts: they were added so that the complete output is read (#13091, #14820), which Selenium Manager relies on. Waiting while bytes still arrive keeps that.
Measured with a
/bin/shprocess that prints a line, leavessleep 30 &holding stdout, and exits after 1 s (macOS, JDK 25):Follow-up commit, from the review findings:
copyOutputTostream, counts as output, so the quiet period cannot cut off output that is still being forwarded.DriverServiceclosed its log file while a child of the driver still writes, the forwarder keeps reading the pipe and discards the rest, so the child cannot block on a full pipe.Tests in
ExternalProcessTest, disabled on Windows since they use/bin/sh:waitForReturnsWhenAChildKeepsTheOutputOpenandshutdownReturnsWhenAChildKeepsTheOutputOpen: fail after 11,035 ms and 10,027 ms without the change.waitForKeepsWaitingWhileASlowCopyIsInProgressandoutputIsStillReadWhenTheCopyFails: fail without the follow-up commit.All 12 tests in
ExternalProcessTestpass. I ran them locally with the JUnit console launcher rather than Bazel.🤖 AI assistance
💡 Additional Considerations
The 500 ms quiet period is a constant. Happy to make it configurable, or change the value, if you prefer.
🔄 Types of changes