Private Networking ECONNREFUSED
athusrv
HOBBYOP

a month ago

I am trying to reach my Python backend from my NextJS app using server actions and private networking but I am getting the error below:

[cause]: Error: connect ECONNREFUSED fd12:3492:8245:0:e000:10:4221:abc5:8080
      at <unknown> (Error: connect ECONNREFUSED fd12:3492:8245:0:e000:10:4221:abc5:8080) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: 'fd12:3492:8245:0:e000:10:4221:abc5',Error: connect ECONNREFUSED fd12:3492:8245:0:e000:10:4221:abc5:8080
    port: 8080
    at <unknown> (Error: connect ECONNREFUSED fd12:3492:8245:0:e000:10:4221:abc5:8080)
  }
    at W.from (.next/server/app/login/page.js:1:14854)
}
    at u.<anonymous> (.next/server/app/login/page.js:3:13563)
    at n.<computed> (.next/server/app/login/page.js:4:31868)
    at bQ.request (.next/server/app/login/page.js:3:26036)
    at async bY (.next/server/app/login/page.js:3:32064)
    at async m (.next/server/app/login/page.js:3:59901)
    at async p (.next/server/app/login/page.js:4:1860) {
  isAxiosError: true,
  code: 'ECONNREFUSED',
  config: [Object],
  request: [Writable],
  digest: '1696790594',

Already verified the backend port and it's running at port 8080 per the logs. The env var is set this way: `http://${{api.RAILWAY%5FPRIVATE%5FDOMAIN}}:8080`.

Solved$10 Bounty

Pinned Solution

This means your backend is bound to an IPv4 address. The address Axios is trying to hit is IPv6. You need to update your python backend's start command or configuration to bind to :: (handles both IPv4 and IPv6 traffic) instead of 0.0.0.0.

9 Replies

Status changed to Open Railway about 1 month ago


irazvan2745
FREE

a month ago

If you use the public domain does it work?


athusrv
HOBBYOP

a month ago

It does


irazvan2745
FREE

a month ago

can you add a small console log to see what that env variable is


Anonymous
FREE

a month ago

..


This means your backend is bound to an IPv4 address. The address Axios is trying to hit is IPv6. You need to update your python backend's start command or configuration to bind to :: (handles both IPv4 and IPv6 traffic) instead of 0.0.0.0.


darseen

This means your backend is bound to an IPv4 address. The address Axios is trying to hit is IPv6\. You need to update your python backend's **start command** or **configuration** to bind to `::` (handles both IPv4 and IPv6 traffic) instead of `0.0.0.0`.

athusrv
HOBBYOP

a month ago

It works for apps talking on the private network. My NextJS app is now able to interact with the backend, however, looks like public networking stopped to work when I added this binding. Any clue why? I need the public network for the mobile app running on Android and iOS devices.


Your python server is likely binding to IPv6 only and dropping IPv4 traffic. You need to bind your server to both interfaces (0.0.0.0 and ::) in this case. What is your python server so I can help you with it?


athusrv
HOBBYOP

a month ago

You're right.

I was using uvicorn alone but with the need to bind to both IPv6 and IPv4, I decided to go with gunicorn with uvicorn workers, so I am starting my backend like sh -c 'gunicorn src.main:app -k uvicorn.workers.UvicornWorker --bind [::]:$PORT' .

It's working fine now.

As uvicorn relies on Python's socket behavior, dual-stacking support in uvicorn depends on OS-level socket config. It seems like this kernel config is set to 1: net.ipv6.bindv6only

I didn't want to mess with these internal tools so I preferred to go with gunicorn + uvicorn workers. It looks like gunicorn creates sockets differently so --bind [::]:$PORT works for both IPv6 and IPv4.


darseen

This means your backend is bound to an IPv4 address. The address Axios is trying to hit is IPv6\. You need to update your python backend's **start command** or **configuration** to bind to `::` (handles both IPv4 and IPv6 traffic) instead of `0.0.0.0`.

athusrv
HOBBYOP

a month ago

This answer led me to solving the problem. I am accepting this answer as the solution, but for others, note the rest of this thread for a complete set of actions you need to take.


Status changed to Solved brody about 1 month ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...