ngrok icon indicating copy to clipboard operation
ngrok copied to clipboard

RequestError: connect ECONNREFUSED 127.0.0.1:4040

Open yashwanth2714 opened this issue 1 year ago • 8 comments

Hello Team,

I occasionally encounter the following error. Could you please help me in resolving it?

image

Code:

image

yashwanth2714 avatar Dec 14 '23 10:12 yashwanth2714

Bump +1

cbstns avatar Dec 19 '23 23:12 cbstns

We're running into the same issue version: 5.0.0-beta.2

samsonquantifi avatar Dec 19 '23 23:12 samsonquantifi

Same error here, with the same version: 5.0.0-beta.2

yoandry-quantifi avatar Dec 19 '23 23:12 yoandry-quantifi

My recommendation to all at this point: check out Ngrok's official NPM package (still not in full version release yet, but has proven solid for me).

@ngrok/ngrok

Here's a working example for Sails.js: https://github.com/neonexus/sails-react-bootstrap-webpack/blob/release/ngrok.js

neonexus avatar Dec 20 '23 04:12 neonexus

Running ngrok in CI and tests have been failing consistently as of yesterday. Also on 5.0.0-beta.2

sonu-relay avatar Dec 21 '23 15:12 sonu-relay

Ran in to the same issue and I could output a clearer, actionable error by trying to launch ngrok directly:

$> node_modules/ngrok/bin/ngrok http 8080

That displayed an ERR_NGROK_4018 error code which led to this explanation:

You must have a valid account and authtoken to perform this operation. Starting on December 19th 2023, all connections to ngrok will require a valid authtoken.

Sign up for an account: https://dashboard.ngrok.com/signup Install your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken

After following those steps I could persist my authtoken by running the following command, replacing <AUTH_TOKEN> with my actual authentication token and the issue was resolved on next run:

$> node_modules/ngrok/bin/ngrok config add-authtoken <NGROK_AUTH_TOKEN>

Of course, if the error is not ERR_NGROK_4018 when launching ngrok manually then a different fix will be needed.

richtr avatar Jan 18 '24 09:01 richtr

Thanks @richtr !!!! it solved my issue as well! 💪🏻 🔥 🥳

tamardu avatar Jan 24 '24 10:01 tamardu

Same issue here. I already have the token in my ngrok.yml file, still getting the error.

I created a small script to replicate the issue:

//index.js
import ngrok from "ngrok";

const hostname = "localhost"
const port = 3000

const main = async () => {
try {
    return await ngrok.connect({ addr: `${hostname}:${port}`, onLogEvent: data => {
      console.log(data)
    }, });
  } catch (error) {
    if (
      typeof error.message === "string" &&
      error.message.includes("`version` property is required")
    ) {
      // await upgradeNgrokConfig(spinner);

      try {
        return await ngrok.connect(port);
      } catch (retryError) {
        console.log(
          `Ngrok failed to create a tunnel for port ${port} after configuration upgrade.\n${retryError}`
        );
        return;
      }
    }
    if (
      typeof error.message === "string" &&
      error.message.includes("connect ECONNREFUSED 127.0.0.1:4041")
    ) {
      console.log(
        `Ngrok failed to create a tunnel for port ${port} because ngrok is already running.\n  You may want to use -t flag to use an existing URL that points to the local dev server.`
      );
      return;
    }
    console.log(`Ngrok failed to create a tunnel for port ${port}.\n${error.message}`);
    return;
  }
}


main()

and this is the error:

node index.js 
t=2024-03-08T17:53:21+0100 lvl=info msg="no configuration paths supplied"
t=2024-03-08T17:53:21+0100 lvl=info msg="using configuration at default config path" path="/Users/REDACTED/Library/Application Support/ngrok/ngrok.yml"
t=2024-03-08T17:53:21+0100 lvl=info msg="open config file" path="/Users/REDACTED/Library/Application Support/ngrok/ngrok.yml" err=nil
t=2024-03-08T17:53:21+0100 lvl=info msg="starting web service" obj=web addr=127.0.0.1:4040
t=2024-03-08T17:53:21+0100 lvl=info msg=start pg=/api/tunnels id=7b8c6a52700738e0
t=2024-03-08T17:53:21+0100 lvl=warn msg="ngrok is not yet ready to start tunnels" pg=/api/tunnels id=7b8c6a52700738e0 err="a successful ngrok tunnel session has not yet been established"
t=2024-03-08T17:53:21+0100 lvl=info msg=end pg=/api/tunnels id=7b8c6a52700738e0 status=503 dur=226.209µs
t=2024-03-08T17:53:21+0100 lvl=eror msg="failed to auth" obj=tunnels.session err="Your ngrok-agent version \"3.0.5\" is too old. The minimum supported agent version for your account is \"3.2.0\". Please update to a newer version with `ngrok update`, by downloading from https://ngrok.com/download, or by updating your SDK version. Paid accounts are currently excluded from minimum agent version requirements. To begin handling traffic immediately without updating your agent, upgrade to a paid plan: https://dashboard.ngrok.com/billing/subscription.\r\n\r\nERR_NGROK_121\r\n"
t=2024-03-08T17:53:21+0100 lvl=eror msg="failed to reconnect session" obj=csess id=49e012e56c5a err="Your ngrok-agent version \"3.0.5\" is too old. The minimum supported agent version for your account is \"3.2.0\". Please update to a newer version with `ngrok update`, by downloading from https://ngrok.com/download, or by updating your SDK version. Paid accounts are currently excluded from minimum agent version requirements. To begin handling traffic immediately without updating your agent, upgrade to a paid plan: https://dashboard.ngrok.com/billing/subscription.\r\n\r\nERR_NGROK_121\r\n"
t=2024-03-08T17:53:21+0100 lvl=eror msg="session closing" obj=tunnels.session err="Your ngrok-agent version \"3.0.5\" is too old. The minimum supported agent version for your account is \"3.2.0\". Please update to a newer version with `ngrok update`, by downloading from https://ngrok.com/download, or by updating your SDK version. Paid accounts are currently excluded from minimum agent version requirements. To begin handling traffic immediately without updating your agent, upgrade to a paid plan: https://dashboard.ngrok.com/billing/subscription.\r\n\r\nERR_NGROK_121\r\n"
t=2024-03-08T17:53:21+0100 lvl=info msg="received stop request" obj=app stopReq="{err:0x140002945a0 restart:false}"
t=2024-03-08T17:53:21+0100 lvl=eror msg="terminating with error" obj=app err="Your ngrok-agent version \"3.0.5\" is too old. The minimum supported agent version for your account is \"3.2.0\". Please update to a newer version with `ngrok update`, by downloading from https://ngrok.com/download, or by updating your SDK version. Paid accounts are currently excluded from minimum agent version requirements. To begin handling traffic immediately without updating your agent, upgrade to a paid plan: https://dashboard.ngrok.com/billing/subscription.\r\n\r\nERR_NGROK_121\r\n"
t=2024-03-08T17:53:21+0100 lvl=crit msg="command failed" err="Your ngrok-agent version \"3.0.5\" is too old. The minimum supported agent version for your account is \"3.2.0\". Please update to a newer version with `ngrok update`, by downloading from https://ngrok.com/download, or by updating your SDK version. Paid accounts are currently excluded from minimum agent version requirements. To begin handling traffic immediately without updating your agent, upgrade to a paid plan: https://dashboard.ngrok.com/billing/subscription.\r\n\r\nERR_NGROK_121\r\n"
t=2024-03-08T17:53:21+0100 lvl=warn msg="failed to check for update" obj=updater err="Post \"https://update.equinox.io/check\": context canceled"
Ngrok failed to create a tunnel for port 3000.

But in my CLI I have the latest version, but if I assume correctly, this package doesn't use my global version but the local version installed in this package.

50bbx avatar Mar 08 '24 16:03 50bbx