Selenium

ChromeDriver hangs with Selenium Server and Xvfb

I have spent several hours working on an issue while running Selenium Server under Xvfb with ChromeDriver.  There would basically be a 30 second timeout when connecting to Selenium Server from WebDriver with this being the exception:

1) Tests\Magium\AbstractTestCase\CoreAssertionTest::testElementDisplayed
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}

Operation timed out after 30001 milliseconds with 0 out of -1 bytes received

/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:89
/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:254
/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:97
/var/lib/jenkins/jobs/Magium (personal)/workspace/lib/WebDriver/WebDriverFactory.php:17
/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/zendframework/zend-di/src/Di.php:547
/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/zendframework/zend-di/src/Di.php:321
/var/lib/jenkins/jobs/Magium (personal)/workspace/vendor/zendframework/zend-di/src/Di.php:265
/var/lib/jenkins/jobs/Magium (personal)/workspace/lib/TestCase/Initializer.php:53
/var/lib/jenkins/jobs/Magium (personal)/workspace/lib/AbstractTestCase.php:70

I strace()ed the process and it came down to a read() on a pipe sitting there, but I could not figure out why.  Eventually I worked my way into the temp directory for the hung process, /tmp/.com.google.Chrome.v0ul8E.  In there is the file chrome_debug.log.   In that file was one entry:

[11259:11259:0412/062020:ERROR:sandbox_linux.cc(334)] InitializeSandbox() called with multiple threads in process gpu-process

Searching Google, I came upon this discussion on GitHub.  The problem they noted was for Docker, and I wasn’t running Docker, but the problem was very similar.  The solution was to set the environment variable: DBUS_SESSION_BUS_ADDRESS=/dev/null.

I made the change to my systemd service file

[Unit]
Description=Selenium
After=xvfb.target

[Service]
Type=simple
User=selenium
PIDFile=/var/spool/selenium/pid/master.pid
EnvironmentFile=-/etc/sysconfig/network
Environment=DISPLAY=:99
Environment=DBUS_SESSION_BUS_ADDRESS=/dev/null
ExecStart=/bin/java -Dwebdriver.chrome.driver=/var/www/selenium/bin/chromedriver -Dwebdriver.chrome.logfile=/home/selenium/chrome.log -Dselenium.LOGGER=/home/selenium/selenium.log -jar /var/www/selenium/bin/selenium-server-standalone-2.53.0.jar
ExecStop=kill `cat /var/spool/selenium/pid/master.pid`

[Install]
WantedBy=multi-user.target

I’ve run about 300 tests so far with no timeouts. Yay!

1 thought on “ChromeDriver hangs with Selenium Server and Xvfb”

Leave a Reply

Your email address will not be published. Required fields are marked *