Skip to content

[test-runner] Race condition when selecting an open port #1951

Open
@justinfagnani

Description

@justinfagnani

The use of portfinder to find an open port allows for a race condition when running multiple parallel instances of wtr.

The way portfinder (and most other open port finding libraries) works is that it attempts to open a given port by starting a server, and if that succeeds it closes the server and returns the port number to the caller. In the time between closing the server and the caller starting it's own server another process can then claim the port. This happens quite easily with port 8000 if two wtrs calls happen very quickly (as might happen with a parallel script runner like wireit :) ).

The best solution we found when building Web Component Tester and polyserve was to move the open port finding in-house by actually trying to start our server and retrying if we failed because of an EADDRINUSE. This way once we found an open port we didn't have to release it and try to claim it again right away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions