R
Railway17mo ago
Faey

Failing healthchecks

My healthchecks are failing and I can't quite figure out why. They work locally and there is no errors in the logs, the service appears to start properly.
Solution:
I've specified the host as 0.0.0.0 now
Jump to solution
32 Replies
Percy
Percy17mo ago
Project ID: fd3c34f8-2314-4d8d-8f79-2ed37386c50d
Faey
FaeyOP17mo ago
fd3c34f8-2314-4d8d-8f79-2ed37386c50d
Brody
Brody17mo ago
what's your healthcheck set to?
Faey
FaeyOP17mo ago
"/health"
Brody
Brody17mo ago
can you show me the code that handles that path
Faey
FaeyOP17mo ago
app.get('/health', (_req, res) => {
if (initialized && featureSwitchesReady) {
res.status(200).send('Healthy');
} else {
res.status(503).send('Starting');
}
});
app.get('/health', (_req, res) => {
if (initialized && featureSwitchesReady) {
res.status(200).send('Healthy');
} else {
res.status(503).send('Starting');
}
});
I have log output for those two variables, I can confirm they are both true The healthcheck is failing with service unavailable, not 503
Brody
Brody17mo ago
looks good so far show me your app.listen code please
Faey
FaeyOP17mo ago
app.listen(process.env['PORT'] ? process.env['PORT'] : 80);
Brody
Brody17mo ago
never seen it done like that before just do process.env.PORT || 8080 I've changed the fallback port to 8080 for when you do local development, it's always best to listen on a non privileged port
Faey
FaeyOP17mo ago
I've modified it to
await app.listen({port:parseInt(process.env['PORT'] || "8080")});
await app.listen({port:parseInt(process.env['PORT'] || "8080")});
to match with fastify's current method signature I'll let you know what the outcome is once the deploy is finished building
Brody
Brody17mo ago
any reason you choose to go against what I said and use ['PORT'] instead of .PORT?
Faey
FaeyOP17mo ago
Oh I missed that part Should be equivalent though
Brody
Brody17mo ago
I wouldn't know, I'm not a js dev
Faey
FaeyOP17mo ago
Just to make sure, I've modified it to match the suggested signature
await app.listen({port:parseInt(process.env.PORT || "8080")});
await app.listen({port:parseInt(process.env.PORT || "8080")});
Brody
Brody17mo ago
looks good
Faey
FaeyOP17mo ago
Still the same, service unavailable
Brody
Brody17mo ago
remove the healthcheck and see what happens, once it redoploys wait a good 60 seconds before hitting the railway domain
Faey
FaeyOP17mo ago
I've figured it out
Brody
Brody17mo ago
do tell
Faey
FaeyOP17mo ago
Seems like the default behaviour changed since my last deploy, without specifying the host as 0.0.0.0 it will listen to localhost only
Brody
Brody17mo ago
that should not be a problem what so ever for fastify localhost means listen on both ipv4 and ipv6 interfaces
Brody
Brody17mo ago
Faey
FaeyOP17mo ago
That will make it listen to 127.0.0.1 and ::1
Brody
Brody17mo ago
according to that chart, that shouldn't be a problem but I guess that's just node for you
Faey
FaeyOP17mo ago
There is some docker shenanigans here too
Brody
Brody17mo ago
but healthchecks work?
Solution
Faey
Faey17mo ago
I've specified the host as 0.0.0.0 now
Faey
FaeyOP17mo ago
Which restored everything
Brody
Brody17mo ago
do you think it would be worthwhile for me to pr another code snippet for fastify to https://docs.railway.app/troubleshoot/fixing-common-errors
Faey
FaeyOP17mo ago
I think it might be worthwhile if only for the odd syntax that fastify uses
Brody
Brody17mo ago
noted have a nice day/night!
Faey
FaeyOP17mo ago
You too! Thanks for the help
Want results from more Discord servers?
Add your server