a year ago
I just spent hours trying to debug 502s on every request: "failed to forward request to upstream: connection refused". Tried different configurations and logging to ensure I was using the PORT correctly, uvicorn, hypercorn, railway.json etc. I then randomly tried deleting and regenerating my public domain, and it that fixed it. Pretty nasty bug IMO. JFYI
15 Replies
a year ago
Second this, went through the same exact experience.
a year ago
Just like to note that this isn't a bug, OP has their domain pointed at the wrong port.
a year ago
I guess I had the same wrong port as the OP and didn’t realise it. Perhaps this could be addressed by adding something to tell people to check their port in the custom domain setting to the Fixing Common Errors page? https://docs.railway.app/guides/fixing-common-errors
a year ago
I don’t recall pointing any domain or port. Do you guys read the port from the initial start command or something? I do recall the app worked my first try on hardcoded default port, and broke around when I switched to using the recommended env var $PORT
a year ago
Yep, it is detected when you first deploy your app, at this time it would be up to the user to keep the port up to date with what the app actually listens on.
a year ago
I’m not following. The docs say to configure the app to listen to $PORT, which I did, and I got 502s until I recreated the domain. Are you saying to do something different?
a year ago
This is probably the source of the confusion then. I didn’t set any domain port, it seems that may have been inferred by railway at creation. Unfortunately none of this is documented.
a year ago
Yep, as previously mentioned this has yet to be documented, but for your context -
Attachments
a year ago
So in this example, the app should be listening on 8080, but the value of $PORT passed into the environment is not 8080?
a year ago
The value of PORT is 8080, and that's what the domain should be pointing to, you have it correct right now.
Previously when you configured your app to listen on PORT, your app was then listening on 8080, but your domain was not pointing to 8080.
a year ago
Ok, thank you for explaining to me, but unfortunately I am still confused. If the app should listen on $PORT, shouldn’t railway be passing in the correct value for PORT? Otherwise… what’s the point of the env var? If that’s how it works seems more straightforward to tell the user to make sure the PORTs match.
a year ago
The correct value for PORT is 8080 and that is what Railway has passed your app, and that is what your app was listening on.
PORT has nothing to do with the port you set your domain to, at this time it is up to the user to make sure the port setting for their domain is correct.
a year ago
Ok… I don’t think I ever set that, I just left it at default. Interesting that there’s a UI that allows it to be set to the “wrong” value. Well, thanks for the info, this is very, very good to know 
