headless
headless copied to clipboard
Run Concurrently (using different ports?)
First off, thanks for the awesome gem.
I want to use headless to run concurrent selenium builds using this gem, and I see that xvfb
should allow being passed an --auto-servernum
flag at runtime. This will presumably prevent the following collision error I'm seeing currently when running concurrent builds:
Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:7057 (Connection refused - connect(2) for "127.0.0.1" port 7057)
I've tried invoking headless using a random display each time inside a sidekiq worker with concurrency of 3, but I get similar errors
headless = Headless.new(display: rand(100))
headless.start
Does using Headless.new(autopick: true)
in the sidekick worker solve your problem? That should choose the first available display number.
(BTW, the error is from Selenium, not Xvfb, and it means that Selenium failed to boot - this might be caused by missing Xvfb, but other things too - like a Selenium port conflict.)
@leonid-shevtsov isn't autopick: true
the default?
It would seem that passing display:
key will conflict with the autopick
settings.
I do have Xvfb
installed, and do not have this error when running a single thread, only when I introduce concurrent workers.
How do you start your Selenium? Do you specify different ports for each Selenium instance?
@leonid-shevtsov simply like this:
def driver
@driver ||= Selenium::WebDriver.for :firefox
end
should I be specifying a unique port each time if I am running on concurrent workers?
@leonid-shevtsov @Lordnibbler I can confirm that there is issue to run scripts which uses selenium+headless concurrently. I've writed small script which reproduces that kind of error: http://pastebin.com/96h2WEuf To reproduce error: run the script in two different consoles, first with command line parameter "10" (without quotes), second with command line parameter "1". Then see what's happening after second script finish.
Looks like using different display numbers solves this issue. But I think in that case it's better to run Xvfb one time before starting ruby scripts, there is no need to start/stop Xvfb which is performed when you executing headless.start / headless.destroy (destroy also occurs on_exit automatically)