ECONNREFUSED in helloworld example

Hi there,

I am trying to get the hello world example running and followed the steps from the chat tutorial. However, I got stuck with this step:
Hello World

After installing the node manager, the cli, node.js and npm, I pulled the hello world repo to my desktop and executed the commands in the tutorial.

git clone https://github.com/Actyx/quickstart.git
# cd quickstart/hello-world # curiously, there is no such folder
npm install
npm start

The start command results in this error:

PS C:\Users\jesko\Desktop\quickstart> npm start

> actyx-quickstart@1.0.0 start

nect ECONNREFUSED ::1:4454
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.exports.v2getNodeId (C:\Users\user\Desktop\quickstart\node_modules\@actyx\sdk\lib\v2\utils.js:48:12)
    at Object.of (C:\Users\user\Desktop\quickstart\node_modules\@actyx\sdk\lib\actyx.js:39:24)
    at Object.mkPond [as of] (C:\Users\user\Desktop\quickstart\node_modules\@actyx\pond\lib\pond.js:255:19)

After checking with netstat, the 4454 port seems to be in use by actyx:

[actyx.exe]                    TCP    127.0.0.1:4454          0.0.0.0:0              LISTENING

Also the service is running according to the Windows Service Manager and the node manager can create and connect nodes. The Firewall ist also open for the Actyx service.

Machine:
Windows 10 Pro

ax --version
Actyx CLI 2.5.0-2ebbb20ade6c39a785699d34e9ff02dc9d46acfa-windows-x86_64-release
node --version
v17.3.1
npm --version
8.3.1

I am not sure if i am on the right track, any ideas in how to get the hello world example running?

Thank you!

Edit:
Updated the netstat check, I misread the output

1 Like

Hi Jesko,

I am happy to help figure this out. A couple of things…

1. Log files

Could you send me at oliver@actyx.com (or post here) the actyx-service.err.log file which should be in C:\Program Files\Actyx\Node?

2. Test the API

Could you run Invoke-RestMethod -Uri "http://localhost:4455/api/v2/node/id" in PowerShell and paste the output here?

3. Provide custom API endpoint to the Nodejs application

Set the AX_STORE_URI environment variable to localhost:4454/api/v2 before running npm run start. Here is how you can do it with PowerShell

PS C:\Users\Oliver\Temp\quickstart> $Env:AX_STORE_URI="localhost:4454/api/v2"
PS C:\Users\Oliver\Temp\quickstart> npm run start

> actyx-quickstart@1.0.0 start
> ts-node index

Published: Hello 1 [0000000000009191/EDZOdjSv3ixiigKWevQfYr7fzRGFfYh.2LrOKz6WF/Y-0]
Received:  Hello 1
Published: Hello 2 [0000000000009192/EDZOdjSv3ixiigKWevQfYr7fzRGFfYh.2LrOKz6WF/Y-0]
Received:  Hello 2

Cheers,
Oliver

Hi oli,

Thank you for your help!

1. Log files

I sent it via E-Mail as it is too long for posting here.

2. Test the API

> Invoke-RestMethod -Uri "http://localhost:4455/api/v2/node/id"
Invoke-RestMethod : Unable to connect to the remote server
At line:1 char:1
+ Invoke-RestMethod -Uri "http://localhost:4455/api/v2/node/id"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

3. Provide custom API endpoint to the Nodejs application

PS C:\Users\jesko\Desktop\quickstart> $Env:AX_STORE_URI="localhost:4454/api/v2"
PS C:\Users\jesko\Desktop\quickstart> npm run start

> actyx-quickstart@1.0.0 start
> ts-node index

Error: Error: unable to connect to Actyx at http://localhost:4454/api/v2/node/id. Is the service running? -- Error: request to http://localhost:4454/api/v2/node/id failed, reason: connect ECONNREFUSED ::1:4454
    at C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\sdk\lib\v2\utils.js:56:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.exports.v2getNodeId (C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\sdk\lib\v2\utils.js:48:12)
    at Object.of (C:\Users\user\Desktop\quickstart\node_modules\@actyx\sdk\lib\actyx.js:39:24)
    at Object.mkPond [as of] (C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\pond\lib\pond.js:255:19)

Service seems to be running:
Service

Thanks!

So from the results of 2. and 3. it is clear that the Actyx API isn’t listening on 4454. And that even though the logs show the following

2022-01-19T06:57:12.768697Z  INFO API_BOUND: API bound to 127.0.0.1:4454.

So I am thinking that maybe something else is taking over the port after node startup? Someone may be using SO_REUSEADDR and we aren’t using SO_EXCLUSIVEADDRUSE (which would probably be a bug).

Could you please try the following and post the results?

  1. Stop the Actyx service
  2. Edit the C:\Program Files\Actyx\Node\actyx-service.xml file by changing the line
    <startarguments>--background</startarguments> to
    <startarguments>--background --bind-api 7575</startarguments>
  3. Restart the Actyx service
  4. Run through steps 2. and 3. from above again, but using port 7575 instead of 4454 (I used 4455 above by mistake in step 2).

Thanks,
Oliver

Thats what I got:

2. Test the API

PS C:\Users\jesko\Desktop> Invoke-RestMethod -Uri "http://localhost:7575/api/v2/node/id"
0pyUQG676DwwPRACFJYoeVHy9lmkpS5ZgUzjLSa3lAg

3. Provide custom API endpoint to the Nodejs application

PS C:\Users\jesko\Desktop\quickstart> $Env:AX_STORE_URI="localhost:7575/api/v2"
PS C:\Users\jesko\Desktop\quickstart> npm run start

> actyx-quickstart@1.0.0 start
> ts-node index

Error: Error: unable to connect to Actyx at http://localhost:7575/api/v2/node/id. Is the service running? -- Error: request to http://localhost:7575/api/v2/node/id failed, reason: connect ECONNREFUSED ::1:7575
    at C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\sdk\lib\v2\utils.js:56:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.exports.v2getNodeId (C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\sdk\lib\v2\utils.js:48:12)
    at Object.of (C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\sdk\lib\actyx.js:39:24)
    at Object.mkPond [as of] (C:\Users\jesko\Desktop\quickstart\node_modules\@actyx\pond\lib\pond.js:255:19

I also pulled the recent changes from the git repo.

Hi Jesko,

can you run 3. again, but with $Env:AX_STORE_URI="127.0.0.1:7575/api/v2" please.

Thanks,
Oliver

Hi Oliver,

that seems to work on port 7575!
I also tested it with the default port (4454) and it runs perfectly as well.

So the trick was to replace the localhost with 127.0.0.1.

I will remember it for the next time.

Thank you very much!
Jesko

Ok, perfect. I will open a ticket on our end to investigate why you couldn’t access it using an ipv6 address.

Cheers,
Oliver

1 Like