Application failed to respond - 502 Error
wesleywas
PROOP

a year ago

Hey guys,

I am hosting a Node.js script on Railway since a long time now, and everything has always been working fine.

Recently, without changing the codebase or anything, for whatever reason at totally random moments, my query to my Railway hosted endpoint will result in a "502: Application failed to respond".

The queries go through 98% of the time, just sometimes, for whatever reasons, they don't.

I've already looked for help on the forum, read that page (https://docs.railway.app/guides/fixing-common-errors) a couple times and looked at all the topics on Railway's forum.

Here is how I start my Node.js script:

const port      = process.env.PORT || 3000;
app.listen(port, "0.0.0.0", () => {
    console.log(`Now listening on port ${port}`);
});

Which I think is the right way to do it.

Here's my start script in the package.json:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start":  "node index.js"
}

Could someone help me?

Thanks!

Wes

Solved

4 Replies

brody
EMPLOYEE

a year ago

Hello,

It looks like the path that is failing is exclusively /getDbContent could you shine some light on what this path does, because it seems like it's failing to respond to the incoming request -

Attachments


Status changed to Awaiting User Response Railway about 1 year ago


wesleywas
PROOP

a year ago

Hi brody, thanks so much for your answer!

It's basically just using 'node-fetch' to query an other endpoint, and returns the result of that call.

Here is what it does:

app.post('/getDbContent', isAuth, async (req, res, next) => {
    //Some variables definitions before this
    //postData is defined below
    let result = await postData(full_url, app_id, app_version, cookie, appObj);
    res.status(200).send(result);
}

Here is what postData does:

async function postData(url, app_id, app_version, cookie, appObj){
    const response = await fetch(url, {
        method: "POST",
        body: JSON.stringify(obfuscation(appObj)),
        headers: {
            "accept": "application/json, text/javascript, */*; q=0.01",
        },
    });;
    return response.json();
}

Does that help?


Status changed to Awaiting Railway Response Railway about 1 year ago


brody
EMPLOYEE

a year ago

It does, I see there is no error handling or logging, perhaps that fetch was failing and then express is dropping the request because there is no recover code path?


Status changed to Awaiting User Response Railway about 1 year ago


brody
EMPLOYEE

a year ago

Going to mark this as solved, if you continue to experience this we would need a reproducible example otherwise we wouldn't be able to help here.


Status changed to Solved brody about 1 year ago


Loading...