Skip to content

example-wait-on fails on GitHub waiting for localhost #802

@MikeMcC399

Description

@MikeMcC399

IMPORTANT

  • Please see the issue wait-on issues with Node.js 18 #811 for a better set of workarounds. The descriptions below were before I got into understanding the root cause better. I don't however want to delete the text in this issue even if it is no longer up to date. (Mar 2, 2023.)

The example-wait-on workflow fails on GitHub in some jobs waiting for localhost after the ubuntu-22.04 runner was migrated to use Node.js 18 as default. GitHub reports that the migration deployed on Feb 18, 2023 on the same date that example-wait-on began failing some of its test jobs. Other test jobs waiting for localhost succeed however.

Problem description

The workflow .github/workflows/example-wait-on.yml fails in jobs:

  • wait-using-custom-command-v9 / wait-using-custom-command
  • wait-on-vite-v9 / wait-on-vite

The last successful run was on Feb 17, 2023 with ubuntu-22.04 image Version: 20230206.1 using the default Node.js 16.19.0.
The first failed run was on Feb 18, 2023 ubuntu-22.04 image Version: 20230217.1 using the default Node.js 18.14.1.

See https://github.com/cypress-io/github-action/actions/workflows/example-wait-on.yml for workflow history.

wait-using-custom-command

          working-directory: examples/react-scripts
          start: npm start
          wait-on: 'npx wait-on --timeout 5000 http://localhost:3000'

shows

You can now view example-react-scripts in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://10.1.0.40:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

webpack compiled successfully
npm WARN exec The following package was not found and will be installed: wait-on@7.0.1
Error: Timed out waiting for: http://localhost:3000
    at /home/runner/.npm/_npx/04d57496964ca6d1/node_modules/wait-on/lib/wait-on.js:132:31

with wait-on --verbose enabled it shows that wait-on is trying to connect to the IPv6 address ::1, however the react server is only listening on the IPv4 address 127.0.0.1:

npm WARN exec The following package was not found and will be installed: wait-on@7.0.1
waiting for 1 resources: http://localhost:3000
making HTTP(S) head request to  url:http://localhost:3000 ...
  HTTP(S) error for http://localhost:3000 Error: connect ECONNREFUSED ::1:3000

... ECONNREFUSED repeated multiple times

wait-on(1747) Timed out waiting for: http://localhost:3000; exiting with error
Error: Timed out waiting for: http://localhost:3000

wait-on-vite

          working-directory: examples/wait-on-vite
          start: npm run dev
          wait-on: 'http://localhost:5173'

shows

waiting on "http://localhost:5173" with timeout of 60 seconds
/usr/local/bin/npm run dev

> example-wait-on-vite@2.0.0 dev
> vite


  VITE v4.0.4  ready in 261 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
http://localhost:5173 timed out on retry 91 of 3, elapsed 90270ms, limit 90000ms
Error: connect ECONNREFUSED 127.0.0.1:5173

Investigation

GitHub ubuntu-22.04 image Version: 20230217.1 is set up as follows:

/etc/hosts

Run cat /etc/hosts
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.0.1 cpu-pool.com
127.0.0.1 MiningMadness.com
127.0.0.1 stratum-na.rplant.xyz
127.0.0.1 do-dear.com
127.0.0.1 web.do-dear.com
127.0.0.1 git.workflows.live
10.1.0.51 fv-az589-316.vc0434dfxmkevoezlasxvobd2h.cx.internal.cloudapp.net fv-az589-316

loopback

Run ip address show lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

Discussion

It is unclear why the wait-on step is causing problems using localhost on GitHub where Cypress manages to successfully test using localhost after the wait-on step when localhost has been substituted by a non-ambiguous alternative (see Workaround section below). Running Cypress tests locally succeeds. So the problem is only on GitHub.

A default installation of Ubuntu only assigns localhost to the ip4 address 127.0.0.1, not to the ip6 address ::1. GitHub however has ::1 localhost ip6-localhost ip6-loopback set up in addition.

Similar issues on GitHub have already been reported in:

The example-wait-on workflow uses different combinations of servers and wait-on providers to monitor the availability of a server on the network address localhost. Some succeed others fail.

Code Server Wait-on provider Result
examples/wait-on node built-in success
examples/react-scripts react-scripts built-in success
examples/react-scripts react-scripts npm wait-on failure
examples/wait-on-vite vite built-in failure

Workarounds

Use specific localhost

Tie tests to Node.js 16

Alternatively: If the failing tests are reverted to running under Node.js 16, then they succeed. Add the following:

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 16

Suggestion

Replace the generic term localhost by a specific reference:

  • react-scripts 127.0.0.1
  • wait-on-vite ip6-localhost

for these webserver which are not listening on both IP stacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions