# Unexpected error: connect ECONNREFUSED 127.0.0.1:443

**URL:** <https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507>\
**Category:** Help me!\
**Tags:** setup\
**Created:** [May 17, 2021, 9:53pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507 "2021-05-17T21:53:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![schalkwijk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/schalkwijk/32/2225_2.png) [@schalkwijk](https://community.forestadmin.com/u/schalkwijk)\
**Post date:** [May 17, 2021, 9:53pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/1 "2021-05-17T21:53:35Z")

</div>

I’m migrating to forest admin 7 and I’m running in to an issue while using the forest agent on my localhost. I can no longer connect to forest admin locally, even though this was working before. This issue was first identified here: [Authentication error after migrating to forest-express-sequelize v7 - #3 by agarbund](https://community.forestadmin.com/t/authentication-error-after-migrating-to-forest-express-sequelize-v7/2440/3), but it appears that the poster fixed the problem but did not post their solution.

## Failure Logs

```javascript
[forest] 🌳🌳🌳 Unable to register the client
{
  "configuration": {
    "authorization_endpoint": "https://api.forestadmin.com/oidc/auth",
    "device_authorization_endpoint": "https://api.forestadmin.com/oidc/device/auth",
    "claims_parameter_supported": false,
    "claims_supported": [
      "sub",
      "email",
      "sid",
      "auth_time",
      "iss"
    ],
    "code_challenge_methods_supported": [
      "S256"
    ],
    "end_session_endpoint": "https://api.forestadmin.com/oidc/session/end",
    "grant_types_supported": [
      "authorization_code",
      "urn:ietf:params:oauth:grant-type:device_code"
    ],
    "id_token_signing_alg_values_supported": [
      "HS256",
      "RS256"
    ],
    "issuer": "https://api.forestadmin.com",
    "jwks_uri": "https://api.forestadmin.com/oidc/jwks",
    "registration_endpoint": "https://api.forestadmin.com/oidc/reg",
    "response_modes_supported": [
      "query"
    ],
    "response_types_supported": [
      "code",
      "none"
    ],
    "scopes_supported": [
      "openid",
      "email",
      "profile"
    ],
    "subject_types_supported": [
      "public"
    ],
    "token_endpoint_auth_methods_supported": [
      "none"
    ],
    "token_endpoint_auth_signing_alg_values_supported": [],
    "token_endpoint": "https://api.forestadmin.com/oidc/token",
    "request_object_signing_alg_values_supported": [
      "HS256",
      "RS256"
    ],
    "request_parameter_supported": false,
    "request_uri_parameter_supported": true,
    "require_request_uri_registration": true,
    "claim_types_supported": [
      "normal"
    ]
  },
  "registration": {
    "redirect_uris": [
      "http://localhost:3310/forest/authentication/callback"
    ],
    "token_endpoint_auth_method": "none"
  },
  "error": {
    "name": "RequestError",
    "code": "ECONNREFUSED",
    "timings": {
      "start": 1621288102003,
      "socket": 1621288102005,
      "lookup": 1621288102005,
      "error": 1621288102006,
      "phases": {
        "wait": 2,
        "dns": 0,
        "total": 3
      }
    }
  }
}
[forest] 🌳🌳🌳 Unexpected error: connect ECONNREFUSED 127.0.0.1:443
{
  "name": "RequestError",
  "code": "ECONNREFUSED",
  "timings": {
    "start": 1621288102003,
    "socket": 1621288102005,
    "lookup": 1621288102005,
    "error": 1621288102006,
    "phases": {
      "wait": 2,
      "dns": 0,
      "total": 3
    }
  },
  "stack": "RequestError: connect ECONNREFUSED 127.0.0.1:443\n at ClientRequest.<anonymous> (/Users/slopes/forerunner/crs-dashboard/node_modules/openid-client/node_modules/got/dist/source/core/index.js:956:111)\n at Object.onceWrapper (node:events:483:26)\n at ClientRequest.emit (node:events:388:22)\n at ClientRequest.EventEmitter.emit (node:domain:470:12)\n at ClientRequest.origin.emit (/Users/slopes/forerunner/crs-dashboard/node_modules/openid-client/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)\n at TLSSocket.socketErrorListener (node:_http_client:486:9)\n at TLSSocket.emit (node:events:376:20)\n at TLSSocket.EventEmitter.emit (node:domain:470:12)\n at emitErrorNT (node:internal/streams/destroy:188:8)\n at emitErrorCloseNT (node:internal/streams/destroy:153:3)\n at processTicksAndRejections (node:internal/process/task_queues:80:21)\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1138:16)\n at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:131:14)"
}

```

## Context

Please provide any relevant information about your setup.

- Package Version: 7.0.0
- Express Version: 4.16.4
- Sequelize Version: 6.5.0
- Database Dialect: postgres
- Database Version: 11.10

Note that I can curl / wget `api.forestadmin.com` just fine from my localhost, so I’m not entirely sure what’s going on.

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [May 18, 2021, 6:57am UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/2 "2021-05-18T06:57:05Z")

</div>

Hello @schalkwijk, welcome in the community 🥳

During authentication, your agent is trying to connect to `https://api.forestadmin.com`, which, in your case, seems redirected to `127.0.0.1`.

Could you please share with us the configuration variables that you set (please obfuscate the secrets before posting them).

Do you have access to `http://api.forestadmin.com` in the same context than the agent that you are running?

---

<div class="post-metadata">

**Author:** ![agarbund](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/agarbund/32/502_2.png) [@agarbund](https://community.forestadmin.com/u/agarbund)\
**Post date:** [May 18, 2021, 10:41am UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/3 "2021-05-18T10:41:31Z")

</div>

@schalkwijk I didn’t really fixed that issue but rather identified it’s caused by embedding Forest app within Nest.js framework Express instance. I haven’t yet had a chance to investigate it further but it can be fixed by manually retrieving client id and setting `FOREST_CLIENT_ID` env variable as described [here](https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v7#running-up-multiple-server-instances).

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [May 18, 2021, 11:25am UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/4 "2021-05-18T11:25:48Z")

</div>

@schalkwijk are you running your agent inside `Nest.js`?

---

<div class="post-metadata">

**Author:** ![schalkwijk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/schalkwijk/32/2225_2.png) [@schalkwijk](https://community.forestadmin.com/u/schalkwijk)\
**Post date:** [May 18, 2021, 1:32pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/5 "2021-05-18T13:32:45Z")

</div>

@agarbund, thanks for the explanation!

@GuillaumeGautreau, thanks for the warm welcome! I’m not using `Nest.js`, no - just running my agent inside a pretty simple express server. Currently, it’s running on my Mac (not even within docker) and I can reach `api.forestadmin.com` from my terminal with a `curl`:

```javascript
$ curl https://api.forestadmin.com/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>

```

I believe I only have two Forest-related environment variables set:

```javascript
FOREST_ENV_SECRET=XXXXXXXXXX
FOREST_AUTH_SECRET=XXXXXXXXXX

```

Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [May 18, 2021, 1:43pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/6 "2021-05-18T13:43:41Z")

</div>

Can it be related to this problem:

- [RequestError: connect ECONNREFUSED 127.0.0.1:443 · Issue #320 · panva/node-openid-client · GitHub](https://github.com/panva/node-openid-client/issues/320)

It seems that third-party libraries can mess up with connections launched by `openid-client` which we are using under the hood.

---

<div class="post-metadata">

**Author:** ![schalkwijk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/schalkwijk/32/2225_2.png) [@schalkwijk](https://community.forestadmin.com/u/schalkwijk)\
**Post date:** [May 18, 2021, 1:55pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/7 "2021-05-18T13:55:31Z")

</div>

Oh, wow - good find, @GuillaumeGautreau! I’ll see if I can’t figure out which dependency is causing the issue, if indeed that’s what’s happening here. I’ll ping this thread once I’ve figured it out.

---

<div class="post-metadata">

**Author:** ![schalkwijk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/schalkwijk/32/2225_2.png) [@schalkwijk](https://community.forestadmin.com/u/schalkwijk)\
**Post date:** [May 18, 2021, 11:34pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/8 "2021-05-18T23:34:47Z")

</div>

@GuillaumeGautreau, that was it - `@google/maps` was causing the issue, and upgrading it removed that particular problem. I’m now encountering another issue, though - I still can’t log in to my admin portal, and there isn’t any obvious failure anywhere so I am unsure as to how to proceed.

Here’s a screenshot of the error I’m seeing:  
 ![Screen Shot 2021-05-18 at 6.14.02 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/9/93c281e890c4af0d65f7d2b441c40c504987bf87.png)

My network tab shows no failures after I press the `Log in again` button:

 ![Screen Shot 2021-05-18 at 6.14.22 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/0b1c338cc9d8494402b5db2d0e1cb31506038afa.png)

My console also has no failures:  
 ![Screen Shot 2021-05-18 at 6.17.10 PM](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8069f4fa6473509a2507a6ad894902e484821686.png)

I added the `cors` headers and `APPLICATION_URL` environment variables as per [this document](https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v7#breaking-changes), and I am not using a `FOREST_CLIENT_ID`. This issue happens both against my development environment and my production environment.

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [May 19, 2021, 6:38am UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/9 "2021-05-19T06:38:45Z")

</div>

Hi,

What is the response of the callback call? Please obfuscate the token, if any 🙂

---

<div class="post-metadata">

**Author:** ![schalkwijk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/schalkwijk/32/2225_2.png) [@schalkwijk](https://community.forestadmin.com/u/schalkwijk)\
**Post date:** [May 19, 2021, 2:13pm UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/10 "2021-05-19T14:13:58Z")

</div>

@GuillaumeGautreau, your debugging game is on _point_ - my application server was intercepting the authentication callback request and returning my webapp, as opposed to letting the request go through to Forest’s own request handlers. With that resolved, it appears that all is in order - thank you for your time and I hope you have a great week.

---

<div class="post-metadata">

**Author:** ![agarbund](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/agarbund/32/502_2.png) [@agarbund](https://community.forestadmin.com/u/agarbund)\
**Post date:** [May 31, 2021, 10:34am UTC](https://community.forestadmin.com/t/unexpected-error-connect-econnrefused-127-0-0-1-443/2507/11 "2021-05-31T10:34:12Z")

</div>

For anyone else experiencing ECONNREFUSED error on request to 127.0.0.1, run

`npm ls agent-base`

and try to update all of packages which are using `agent-base` package.
