R
Railway16mo 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
Percy16mo ago
Project ID: fd3c34f8-2314-4d8d-8f79-2ed37386c50d
Faey
Faey16mo ago
fd3c34f8-2314-4d8d-8f79-2ed37386c50d
Brody
Brody16mo ago
what's your healthcheck set to?
Faey
Faey16mo ago
"/health"
Brody
Brody16mo ago
can you show me the code that handles that path
Faey
Faey16mo 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
Brody16mo ago
looks good so far show me your app.listen code please
Faey
Faey16mo ago
app.listen(process.env['PORT'] ? process.env['PORT'] : 80);
Brody
Brody16mo 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
Faey16mo 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
Brody16mo ago
any reason you choose to go against what I said and use ['PORT'] instead of .PORT?
Faey
Faey16mo ago
Oh I missed that part Should be equivalent though
Brody
Brody16mo ago
I wouldn't know, I'm not a js dev
Faey
Faey16mo 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
Brody16mo ago
looks good
Faey
Faey16mo ago
Still the same, service unavailable
Brody
Brody16mo ago
remove the healthcheck and see what happens, once it redoploys wait a good 60 seconds before hitting the railway domain
Faey
Faey16mo ago
I've figured it out
Brody
Brody16mo ago
do tell
Faey
Faey16mo 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
Brody16mo ago
that should not be a problem what so ever for fastify localhost means listen on both ipv4 and ipv6 interfaces
Brody
Brody16mo ago
Faey
Faey16mo ago
That will make it listen to 127.0.0.1 and ::1
Brody
Brody16mo ago
according to that chart, that shouldn't be a problem but I guess that's just node for you
Faey
Faey16mo ago
There is some docker shenanigans here too
Brody
Brody16mo ago
but healthchecks work?
Solution
Faey
Faey16mo ago
I've specified the host as 0.0.0.0 now
Faey
Faey16mo ago
Which restored everything
Brody
Brody16mo 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
Faey16mo ago
I think it might be worthwhile if only for the odd syntax that fastify uses
Brody
Brody16mo ago
noted have a nice day/night!
Faey
Faey16mo ago
You too! Thanks for the help
Want results from more Discord servers?
Add your server