Skip to content

findAvailablePort in test.dart / service_worker_test.dart is a race condition and likely causes flaky tests #109474

Closed

Description

@Hixie

A number of tests in service_worker_test.dart and test.dart (starting with those introduced in #82307) use a very race-prone technique for finding a port that violates our style guide.

cc @yjbanov @keyonghan

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    platform-webWeb applications specifically
    P2Important issues not at the top of the work list
    on Aug 12, 2022
  2. yjbanov commented on Aug 12, 2022

    @yjbanov
    Contributor

    Is this where the race is

    Future<int> findAvailablePort() async {
    ?

    What multiple things are racing against each other?
    What would be the best way to find a free port?

  3. Hixie commented on Aug 12, 2022

    @Hixie
    ContributorAuthor

    We could be racing against anything in the OS that happens to open a port at the same time.

    In general the best way to find a port is to ask the OS to allocate you one, and then use it. Often saying "port 0" is the way to do that.

  4. added
    c: flakeTests that sometimes, but not always, incorrectly pass
    team-webOwned by Web platform team
    triaged-webTriaged by Web platform team
    on Jul 7, 2023
  5. mdebbar commented on Oct 19, 2026

    @mdebbar
    Contributor

    Fixed in #194419

  6. github-actions commented on Nov 2, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: flakeTests that sometimes, but not always, incorrectly passplatform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions