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

OutOfMemoryError caused by UnixProcess holding all output written to stdout #427

Closed
cerebrotecnologico opened this issue Apr 7, 2015 · 10 comments

Comments

@cerebrotecnologico
Copy link

The class org.openqa.selenium.os.UnixProcess contains the following method:

private final ByteArrayOutputStream inputOut = new ByteArrayOutputStream();

private OutputStream getOutputStream() {
return drainTo == null ? inputOut
: new MultioutputStream(inputOut, drainTo);
}

The variable inputOut is a ByteArrayOutputStream, holding anything that is written in stdout into an array of bytes. The contents are never eliminated, therefore, all output is accumulated, eventually producing the OutOfMemoryError.

@cerebrotecnologico
Copy link
Author

Hello,
The solution won't solve the OOM error. A new CommandLine is already created every time that a FirefoxBinary is created, CommandLine creates a UnixProcess which creates a new ByteArrayOutputStream.

I see no reason to keep the output into a ByteArrayOutputStream, specially if the output is directed into another stream (drainTo) which is set by the environment variable "webdriver.firefox.log".

Seems to me that the only purpose of the inputOut variable is perhaps for some debugging of UnixProcess, since it is only used by getStdOut(), which returns the contents of all the console output ever produced.

Could we eliminate the method getStdOut() from the class UnixProcess ?

The variable inputOut could be set to System.out (so, by default printing the output of the plugins calling console.print) or something equivalent to org.apache.commons.io.output.NullOutputStream (in this case, by default the output would go into a black hole )

Alternatively, inputOut could keep just the last N bytes of output rather holding the entire console output ever produced.

@lukeis
Copy link
Member

lukeis commented Apr 17, 2015

@cerebrotecnologico that pull request was abandoned and no one has submitted another one. Pull requests appreciated? :)

@ROARy
Copy link

ROARy commented Apr 19, 2015

@cerebrotecnologico another idea would be to let the user of UnixProcess decide what kind of outputstream they want with a setter and set the default to NullOutputStream. An OOM error could still happen if someone uses a ByteArrayOutputStream but then at least the user has control over that.

Generally, isn't it bad to eliminate a public method like getStdOut() from the class's interface?

Side note, "drainTo" isn't actually combined with "inputOut" at any point. They're held and written to in parallel inside a MultioutputStream, for some reason.

@barancev
Copy link
Member

I think we can change ByteArrayOutputStream to CircularOutputStream.

barancev added a commit that referenced this issue Jan 28, 2016
@barancev
Copy link
Member

Fixed by commit d4a21ae

@jsdevel
Copy link

jsdevel commented Feb 27, 2016

I believe the documentation on running firefox needs to be added with d4a21ae. I'm not getting this error locally:

java.lang.NoClassDefFoundError: org/openqa/selenium/io/CircularOutputStream

@jsdevel
Copy link

jsdevel commented Feb 27, 2016

Actually, which maven dependency has org.openqa.selenium.io.CircularOutputStream? I'm not seeing it in standalone.

@lukeis
Copy link
Member

lukeis commented Feb 28, 2016

@jsdevel it's in selenium-remote-driver - http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-remote-driver/2.52.0/selenium-remote-driver-2.52.0.jar

(and it's included in the standalone jar)

@jsdevel
Copy link

jsdevel commented Feb 28, 2016

I don't see it in standalone.

@lukeis
Copy link
Member

lukeis commented Feb 28, 2016

@jsdevel i just downloaded again - http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.0.jar

and "org/openqa/selenium/io/CircularOutputStream.class" is in it.

@lock lock bot locked and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants