Services loose connection on redeploy with private network
madsmhm
PROOP

2 months ago

I have an issue where my services lose connection to my cache layer(Lorien HF) if the caching layer gets redeployed. The services are connected with private network(IPv6) and the cache layer has 2 replicas.

I have read other posts regarding this issue and had it myself(but with a Sveltekit service) and have solved it with setting HOST=:: in the environment variables, which makes sense.

The current problem is that my cache layer is running with NitroJS + Bun(https://nitro.build/deploy/runtimes/bun). If I run the service locally and set NITRO_HOST=::
It will log
"Listening on http://[::]:3000/"

Which seems like the thing I want.
But when I run it on railway it dosen't work. I have also tried to set both NITRO_HOST and HOST to "::" but no luck.

I am pretty sure that this will solve my issue with the connection, but cant "inject" the variable into my service on railway.

Solved$10 Bounty

Pinned Solution

douefranck
FREE

2 months ago

yes your config looks correct on paper. but if it's still failing on railway, the issue is likely that "latest" in bun.lock might not be resolving to nitro v2.12.5+ in your actual deployment, or the environment variables aren't being applied at runtime on railway

to verify, check your railway deployment logs when the service starts up. if nitro is actually reading nitro_host=:: correctly, you should see it log something like "listening on http://[::]:3000" or similar. if it just says "localhost" then the env var isn't being picked up

if the logs do show it's binding to :: but connections still fail after cache layer redeploys, then the problem is something else

6 Replies

douefranck
FREE

2 months ago

hey so, nitro has a confirmed bug where the bun preset completely ignores the nitro_host environment variable, it only reads nitro_port. this is a known issue on their github (issue #3546 from august 2025, still open). the bun preset source code literally doesn't include the hostname parameter in bun.serve() call, so setting nitro_host or host does nothing.

the safest fix is to switch from bun preset to the default node preset which properly supports host configuration. if you absolutely need bun runtime, you'd have to create a custom nitro preset that manually adds hostname: "::" to the bun.serve() options, but that's more complex.

tldr: nitro bun preset is broken for ipv6 host binding, use node preset instead or wait for nitro to fix their bug

doue


madsmhm
PROOP

2 months ago

Hey Doue

Thanks for fast and good reply! I cant seem to find the issue you are referring to, but you summed it up quite good.

Alright, I will consider doing the switch then and just to be clear, if I get the service moved to a new project where private networks runs with IPv4 + IPv6 that wont change a thing right? Because I still dosen't listen on both.

PS: The issue you talked about seems to be fixed in version 2.12.9(https://github.com/nitrojs/nitro/blob/v2.12.9/src/presets/bun/runtime/bun.ts), which will explain why I can get it to work on localhost. Does it maybe seems more like a railway issue?


douefranck
FREE

2 months ago

good catch, the bug was fixed in nitro v2.12.5 (released sept 2, 2025) with pr #3547 titled "bun: respect host and nitro_host". since you're on v2.12.9, you already have the fix, which explains why nitro_host=:: works locally.

so if it works locally but not on railway, check these things:

first, make sure your railway deployment is actually using nitro v2.12.5+ (check your package.json and lock file are committed)

second, verify the nitro_host environment variable is actually set to :: in your railway service settings (not just locally)

third, make sure you're using the bun preset in production on railway

about the ipv4+ipv6 question: correct, moving to a new railway environment with dual stack won't help if your app isn't listening on :: - you still need nitro_host=:: set regardless of whether railway supports ipv4 or ipv6 only. the :: binding is what makes your app accept connections on all interfaces

so since you have the fixed nitro version, just make sure nitro_host=:: is set as an environment variable in your railway service and redeploy


madsmhm
PROOP

2 months ago

Now I found it, thanks!

1. This is bun.lock "nitropack": "latest",
2. Have tested with them both and one by oneHOST="::"  and NITRO_HOST="::"

3. preset: 'bun', and railway.toml

[build]
builder = "RAILPACK"
buildCommand = "bun run build"

[deploy]
region = "europe-west4"
numReplicas = 1
startCommand = "bun --bun run ./.output/server/index.mjs"
sleepApplication = false
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 10

Alright, then my understanding was correct.

Everything seems to be correctly setup?


madsmhm

Now I found it, thanks!1. This is bun.lock "nitropack": "latest",2. Have tested with them both and one by oneHOST="::"  and NITRO_HOST="::"3. preset: 'bun', and railway.toml[build] builder = "RAILPACK" buildCommand = "bun run build" [deploy] region = "europe-west4" numReplicas = 1 startCommand = "bun --bun run ./.output/server/index.mjs" sleepApplication = false restartPolicyType = "ON_FAILURE" restartPolicyMaxRetries = 10Alright, then my understanding was correct. Everything seems to be correctly setup?

douefranck
FREE

2 months ago

yes your config looks correct on paper. but if it's still failing on railway, the issue is likely that "latest" in bun.lock might not be resolving to nitro v2.12.5+ in your actual deployment, or the environment variables aren't being applied at runtime on railway

to verify, check your railway deployment logs when the service starts up. if nitro is actually reading nitro_host=:: correctly, you should see it log something like "listening on http://[::]:3000" or similar. if it just says "localhost" then the env var isn't being picked up

if the logs do show it's binding to :: but connections still fail after cache layer redeploys, then the problem is something else


madsmhm
PROOP

2 months ago

I have now tested with setting nitropack to a fixed version and that actually seems to work!
Now I get the [::] in Listning.

Hopefully this will fix the problem.
Thank you very much.


Status changed to Solved ray-chen about 2 months ago


Loading...