Search code examples
javaseleniumfirefoxgeckodriverheadless

Firefox headless crashing on headless redhat linux machine


I'm trying to run selenium tests on a headless redhat linux build machine using firefox headless. My method to create the driver looks as so:

private static WebDriver createFireFoxDriver() {
    WebDriverManager.firefoxdriver()
            .setup();

    FirefoxOptions options = new FirefoxOptions();
    options.setHeadless(true);
    options.addPreference("browser.download.folderList", 2);
    options.addPreference("browser.download.dir", ABSOLUTE_PATH_TO_FOLDER);
    options.addPreference("browser.download.manager.showWhenStarting", false);
    options.addPreference("browser.helperApps.neverAsk.saveToDisk", "application/json");

    return new FirefoxDriver(options);
}

The error I'm seeing in the log files looks like:

[Parent 65433, Gecko_IOThread] WARNING: pipe error (82): Connection reset by peer: file /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
[Parent 65433, Gecko_IOThread] WARNING: pipe error: Broken pipe: file /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 727

###!!! [Parent][MessageChannel] Error: (msgtype=0x1E0074,name=PBrowser::Msg_StopIMEStateManagement) Channel error: cannot send/recv


###!!! [Parent][MessageChannel] Error: (msgtype=0x1E008F,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv

1579539977190   Marionette  TRACE   [11] Frame script loaded
1579539977191   Marionette  TRACE   [11] Frame script registered
A content process crashed and MOZ_CRASHREPORTER_SHUTDOWN is set, shutting down

I've checked that we have the correct versions of gtk, glib, pango, xorg, and libstdc++ installed on the machine as well. Has anyone run into this problem before with a headless build machine?

Firefox version: 68.4.1 | Selenium version: 3.141.59 | Geckdriver version: 0.26.0

Digging deeper into the test that is causing the crash. Right before the crash occurs the test is clicking on SwaggerUI's API try functionality. No other action on the site causes this crash to happen.


Solution

  • Found a solution that works as well as the root cause.

    When running firefox within a linux docker container, /dev/shm must have at least 2gb. My build machine configuration was not meeting this requirement. Increasing the amount of memory to a value over 2gb solved my problem immediately.

    The reason for this behaviour is that Firefox uses POSIX shared memory which on Linux (according to the shm_open(3) man page) is based on tmpfs (expected to be) mounted on /dev/shm. Open shared memory objects/interfaces can be listed with the ipcs or lsof utilities.