My Express module is losing its url routes

Hello out of a sudden some weeks ago my application bot started to lose its routes that I define dynamically. My components register routes on start up. It worked well no issues there in the past months. But suddenly after some time or I dont know when something triggers it Express loses the routes. I dont know why it does that. For example when I start the server and there will be a route “/commands” defined it works coming back a few hours or so I get a 404 error that the route is not defined/doesn’t exist. My routes are simple app.get routes and I cant explain why this doesnt work anymore as I did not change the code so asking here if Glitch is behaving somehow strange out of a sudden or you dev did some changes that broke it for me and my express approach of routing?

app name: the-alpha-brian

Hey @JaielSoft, I’m sorry for the bother here!

I can’t think of anything we would have changed that would affect this functionality in your project. The only thing that I can think of that would happen between those two moments in time are a project restart (after 5 mins if you don’t have an external service pingins it, at least every 12 hours in any case, and possibly when we recycle a host for some reason - usually for a discord ban).

Is it possible that sometimes the route registration is failing when the project restarts? Are you logging anything when you register the routes and do you see anything in the project logs? It might be worth adding some file logging if you don’t already have it so that any problems persist across restarts.

I will log if the routes have been added then I have connection logs and such yeah will look into it and come back later

1 Like

@cori Hi thanks for the tipp to log. I could identify that they indeed did not register. The reason is that I do heavy work apaprently when Glitch tries to stop the app(saving the state of the bot, all the data etc) Thats not so optimal what I do I know but you send my App a SIGINT or SIGTERM or whatever and my app just takes more than 5 seconds.

Now I have in my app a process watcher, its jsut an object which logs if the process has started correctly and ended correctly, which if you force it to stop after 5 seconds on SIGTERM will make it so it does not end correctly and on next startup my Bot tries to read data from the backup. My components have an init() and a rollback() method and the rollback(), which is called on startup when the process did not end correctly, method does not register any routes which is a big flaw in itself if I am prepared for failed process lifecycles(e.g. app takes longer on finish) but the bigger one is of course the ehavy work on finish which makes Glitch forcing my app to stop of course.

So in short: I identified that I do things the wrong way

@JaielSoft that’s some great sleuthing! If your project is large it’s very possible that it takes a long time to stop because we take a backup during the shutdown process.

When you stop my project I write a 22 mb file synchonously, that is the main reason. I gotta do it differently for sure. I have a flat file where I store user data on and always keep ALL of those data in memory in an object. Which was just a quick solution but have to rewrite it now because you can’t store data of 100k users in a JSON object and read and write to it whenever the app starts/stops. That is the main reason why I am having troubles. I am just doing it all wrong. It went well in the beginning when there wasnt data from hundred of thousands of users in the object though :smiley:

1 Like