Open Bug 1574097 Opened Last month Updated 23 days ago

Bind geckodriver to system-allocated port

Categories

(Testing :: web-platform-tests, enhancement, P3)

Version 3
enhancement

Tracking

(Not tracked)

People

(Reporter: ato, Unassigned)

References

(Blocks 1 open bug)

Details

As can be seen in https://bugzilla.mozilla.org/show_bug.cgi?id=1571426,
geckodriver occasionally fails to bind to the default port in the WPT wdspec tests.

This can be a system related intermittent problem
that we can avoid by binding to port 0
and having the system atomically allocate a port for us.

Priority: -- → P3
Blocks: 1571426

The session fixture at [1] currently takes the port from the configuration fixture [2], which itself tries to find the environment variable WD_PORT, and if not exists defaults to defaults.DRIVER_PORT [3]. Currently this is port 4444.

I assume changing the default to just 0 should be enough? I don't think we should force that behavior, and only fallback to it if WD_PORT hasn't been specified.

[1] https://searchfox.org/mozilla-central/rev/3366c3d24f1c3818df37ec0818833bf085e41a53/testing/web-platform/tests/webdriver/tests/support/fixtures.py#147
[2] https://searchfox.org/mozilla-central/rev/3366c3d24f1c3818df37ec0818833bf085e41a53/testing/web-platform/tests/webdriver/tests/support/fixtures.py#112
[3] https://searchfox.org/mozilla-central/rev/3366c3d24f1c3818df37ec0818833bf085e41a53/testing/web-platform/tests/webdriver/tests/support/defaults.py#9

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+2] from comment #1)

I assume changing the default to just 0 should be enough? I
don't think we should force that behavior, and only fallback to it
if WD_PORT hasn't been specified.

Yes, almost!

We then need the client to parse geckodriver’s output to find out
what the allocated port number is, so it knows where to point the
WebDriver Python client.

It looks like WPT uses the same port randomisation technique as
Selenium for other test types by setting leaving the port kwarg
as None, which will call get_free_port():
https://searchfox.org/mozilla-central/source/testing/web-platform/tests/tools/wptrunner/wptrunner/webdriver_server.py#109

With wdspec this gets set to defaults.DRIVER_PORT, so likely the
easiest fix for bug 1571426 is to ensure that is set to None.
This comes at the slight risk of a race condition, in that the port
is bound by get_free_port() and subsequently released. This is
not atomic, and another process could potentially bind to the port
before geckodriver has time to.

You need to log in before you can comment on or make changes to this bug.