github-action icon indicating copy to clipboard operation
github-action copied to clipboard

wait-on failing because of MaxRedirectsError

Open Floriferous opened this issue 1 year ago • 9 comments

Hello there,

I'm trying to use this github action to run cypress e2e tests on my software. However I'm getting stuck in a redirect loop and don't know how to debug it. There are a bunch of undefined's in the error message as well, so I'm not sure what to do. I can't reproduce it locally either.

Does someone have an idea for how I could address this?

Here's the end of the github action run (currently with DEBUG: '@cypress/github-action':

/usr/local/bin/npm run start-prod
> [email protected] start-prod
> next start
  ▲ Next.js 14.2.4
  - Local:        http://localhost:3000
 ✓ Starting...
 ⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.
 ✓ Ready in 324ms
2024-07-04T10:20:36.034Z @cypress/github-action got error {"name":"MaxRedirectsError","code":"ERR_TOO_MANY_REDIRECTS"}
2024-07-04T10:20:36.034Z @cypress/github-action 2238ms undefined undefined ERR_TOO_MANY_REDIRECTS attempt 2
2024-07-04T10:21:06.513Z @cypress/github-action got error {"name":"MaxRedirectsError","code":"ERR_TOO_MANY_REDIRECTS"}
2024-07-04T10:21:06.513Z @cypress/github-action 32717ms undefined undefined ERR_TOO_MANY_REDIRECTS attempt 3
2024-07-04T10:21:37.045Z @cypress/github-action got error {"name":"MaxRedirectsError","code":"ERR_TOO_MANY_REDIRECTS"}
2024-07-04T10:21:37.045Z @cypress/github-action 63249ms undefined undefined ERR_TOO_MANY_REDIRECTS attempt 4
2024-07-04T10:22:07.574Z @cypress/github-action got error {"name":"MaxRedirectsError","code":"ERR_TOO_MANY_REDIRECTS"}
2024-07-04T10:22:07.574Z @cypress/github-action 93778ms undefined undefined ERR_TOO_MANY_REDIRECTS attempt 5
http://localhost:3000 timed out on retry 5 of 3, elapsed 93778ms, limit 80000ms
2024-07-04T10:22:07.575Z @cypress/github-action Redirected 10 times. Aborting.
2024-07-04T10:22:07.575Z @cypress/github-action MaxRedirectsError: Redirected 10 times. Aborting.
    at Request._onResponseBase (/home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js:51462:35)
Error: Redirected 10 times. Aborting.
    at Request._onResponse (/home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js:51551:24)
    at ClientRequest.<anonymous> (/home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js:51565:23)
    at Object.onceWrapper (node:events:634:26)
    at ClientRequest.emit (node:events:531:35)
    at origin.emit (/home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js:44636:20)
    at HTTPParser.parserOnIncomingClient (node:_http_client:698:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
    at TLSSocket.socketOnData (node:_http_client:540:22)
    at TLSSocket.emit (node:events:519:28)

This is the cypress part of my yaml file:

      - name: Cypress run
        uses: cypress-io/github-action@v6
        env:
          DEBUG: '@cypress/github-action'
        with:
          build: npm run build-test
          start: npm run start-prod
          wait-on: 'http://localhost:3000'
          wait-on-timeout: 50

Floriferous avatar Jul 04 '24 10:07 Floriferous

I ran the exact same setup but replaced:

wait-on: 'http://localhost:3000'

with

wait-on: 'npx wait-on --timeout 60000 http://localhost:3000'

And now it works, very strange.

Floriferous avatar Jul 04 '24 11:07 Floriferous

@Floriferous

Can we close this issue now, since you write that you found a workaround?

MikeMcC399 avatar Jul 13 '24 08:07 MikeMcC399

Well to me there still seems to be an open issue, even though it has a workaround. I've seen repos use a label called "has-workaround" without closing. So I guess it's ultimately a philosophical decision the maintainers have to take :)

Floriferous avatar Jul 14 '24 10:07 Floriferous

@Floriferous

I suspect that the webserver wasn't ready when it was identified as being ready by wait-on: 'http://localhost:3000'. There is some information in the README Debugging waiting for URL to respond about debugging this situation.

I can't say why wait-on: 'npx wait-on --timeout 60000 http://localhost:3000' worked whereas wait-on: 'http://localhost:3000' did not work.

I noticed your logs have a warning, which may or may not be significant:

⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.

I'm not sure where the undefined in the debug log comes from. The action is reporting an error from calls to Node.js network services invoked through the npm module got

        debug(
          `${elapsed}ms ${error.method} ${error.host} ${error.code} attempt ${attemptCount}`
        )

If you want to provide a public repro showing the issue, we can dig in deeper. The benefit would be to understand why there is a failure, but I don't expect this is a bug in the action.

The question about closing or not closing is more a practical one. If the issue is left open it means there is more work to be done and that only makes sense if some further investigation is going to take place and either a documentation change or a fix to the action is expected. If nothing more is going to be done, then closing the issue says the work is finished.

MikeMcC399 avatar Jul 14 '24 10:07 MikeMcC399

You're right, it works for me so I probably won't investigate further either!

Practical decision, let's close this :) Thank you for the thorough response!

Floriferous avatar Jul 14 '24 10:07 Floriferous

Hi, tried your solution and doesn't work for me. Using npx to run the command gave me a strange error, so I installed as a dev dependency and ran with pnpm

pnpm wait-on --timeout 60000 http://localhost:3000

I get the error Error: Timed out waiting for: http://localhost:3000 ... Error: The process '/home/runner/setup-pnpm/node_modules/.bin/pnpm' failed with exit code 1

Chipzstar avatar Sep 10 '25 21:09 Chipzstar

@Chipzstar

Hi, tried your solution and doesn't work for me. Using npx to run the command gave me a strange error, so I installed as a dev dependency and ran with pnpm

pnpm wait-on --timeout 60000 http://localhost:3000

I get the error Error: Timed out waiting for: http://localhost:3000 ... Error: The process '/home/runner/setup-pnpm/node_modules/.bin/pnpm' failed with exit code 1

It sounds like your webserver wasn't ready. If you are looking for additional assistance, please open a new issue (this one is already closed) or use the Cypress community chat on Discord.

MikeMcC399 avatar Sep 11 '25 07:09 MikeMcC399

Re-opening for documentation suggestions from @Chipzstar

MikeMcC399 avatar Sep 12 '25 10:09 MikeMcC399

This error indicates that your server url is redirecting to another url. This can be due to a number of reasons. A common example is if your server is a web application that is auth protected causing redirects to the login page (localhost:3000 -> localhost:3000/login).

In this case the trivial solution would be to set the server url for the wait-on command to one that doesn't trigger a redirect. A health check api endpoint (e.g. wait-on: 'localhost:3000/api/health') is good idea for this since it's usually public with a very low chance of triggering redirects.

For further debugging, you can follow the steps from the debugging-waiting-for-url-to-respond section. If you are still getting this error after running the ping cli on your local machine, edit the dist/index.js file and set followRedirect: false, and test with your server again. Doing this will tell the ping cli to ignore any redirects from your server. This should do one of 2 things:

  1. The Ping CLI successfully responds to your server - meaning you need to use a server URL that doesn't redirect
  2. The Ping CLI will fail with a different error other than MaxRedirectsError - this is good, it means you're making progress :)

Chipzstar avatar Sep 16 '25 14:09 Chipzstar