App sleeping not working??

I've been learning backend dev for a few months, and I'm trying to enable app sleeping on some of my older projects that aren't really in use at all but that I like to visit every now and then to reference. The app sleeping isn't working on any of my projects, and the metrics show that there's pretty constant inbound and outbound traffic. If the frontend site isn't being visited at all, where would this traffic be coming from? I would really like to utilize app sleeping because my bill has been rather high for some apps that are barely in use. I know I could just remove the deployments, but I'd really like to utilize this new feature on some projects if possible.
No description
Solution:
you could try using cloudflare and enabling some of the bot filters. That might reduce some of the hits you get
Jump to solution
74 Replies
Percy
Percy9mo ago
Project ID: cf56f7ac-b7df-4a38-abf6-b3de04633374
corgi mami
corgi mami9mo ago
cf56f7ac-b7df-4a38-abf6-b3de04633374
macwilko
macwilko9mo ago
if the service is exposed to the public web, you'll get a fair amount of bots and things periodically scan it. That'll be enough to wake it up out of app sleeping.
Solution
macwilko
macwilko9mo ago
you could try using cloudflare and enabling some of the bot filters. That might reduce some of the hits you get
corgi mami
corgi mami9mo ago
Is this the case for personal projects hosted on railway where I'm the only one who ever visits them?? I even completely removed one of my projects from railway and redeployed it with a new domain and it instantly started having inbound and outbound traffic even though I hadn't even opened it yet
macwilko
macwilko9mo ago
Yes it’s pretty common, all my projects get inbound traffic from bots. Do you log the requests? If you do you can see what is happening
corgi mami
corgi mami9mo ago
I've been looking at the deploy logs in railway that show when requests are made to the server, and there is no activity there except for when I visit the frontend and make requests. The constant inbound/outbound activity persists even when the logs show no activity
Another Menace
Another Menace9mo ago
The same here. I've joined this server to get help about it. Here's my metrics data. It gets traffic from nowhere. And prevents my app to sleep 😢 I've chosen Railway because of the sleep feature and this issue showed up 😥
No description
Brody
Brody9mo ago
there's honestly not much railway nor the community can do for you besides provide the advice that Mac has
corgi mami
corgi mami9mo ago
Let me know if you're able to figure this out on your end!! I really don't think its bots in my case and my deploy logs aren't showing any activity, so I'm kinda stumped about where this network usage is coming from
Brody
Brody9mo ago
it doesnt have to be http requests, could be anything like next telemetry reporting, port lookups, icmp, ntp, etc
corgi mami
corgi mami9mo ago
Is there a good way to see exactly what it is if it's not http requests??
corgi mami
corgi mami9mo ago
I'm wondering if it has to do with the mongodb database that's also in this project?? The server deploy logs only show my http requests, but the database deploy logs show a connection continuously being accepted and ended, so surely it has to do with this right? I'm not sure why this is happening though or how to stop it. Is this a normal thing with databases in railway??
No description
Brody
Brody9mo ago
do you connect to mongo over the public network?
corgi mami
corgi mami9mo ago
I'm not sure, I don't think so though. I insert the connection string through the private variables in railway which goes to the following:
const mongoose = require('mongoose');
mongoose.set('strictQuery', false);

const mongoDB = process.env.MONGODB_URI || process.env.dev_db_url;

main().catch((err) => console.log(err));
async function main() {
await mongoose.connect(mongoDB);
}
const mongoose = require('mongoose');
mongoose.set('strictQuery', false);

const mongoDB = process.env.MONGODB_URI || process.env.dev_db_url;

main().catch((err) => console.log(err));
async function main() {
await mongoose.connect(mongoDB);
}
Brody
Brody9mo ago
what is MONGODB_URI set to
corgi mami
corgi mami9mo ago
It's set to the connection string for the database in railway mongoDB is part of the project in railway i'm not using it externally
Brody
Brody9mo ago
the public or private connection string?
corgi mami
corgi mami9mo ago
it's not the private one so i'm assuming it must be public
Brody
Brody9mo ago
well there you go
corgi mami
corgi mami9mo ago
What exactly does that mean? Why would that be causing the database to attempt to connect constantly?
Brody
Brody9mo ago
idle timeout either way, your app is connecting to something publicly, that would prevent it from sleeping
corgi mami
corgi mami9mo ago
Okay, I'll definitely do more research on my own to understand the difference between connecting to a database publicly vs privately. I was just taught to use the standard 'MONGO_URL' in railway and haven't had any issues till now, so I have never looked into the private connection string. The private one should still function similarly as far as requests go? Thanks for the help btw!
Brody
Brody9mo ago
you would also not pay any database <--> service egress when using the private network
corgi mami
corgi mami9mo ago
Database:
No description
corgi mami
corgi mami9mo ago
Server:
No description
corgi mami
corgi mami9mo ago
After switching to private networking, outbound traffic has dropped to 0 on both the database and server, but there is still some incoming traffic. Any idea why this is still happening?
Brody
Brody9mo ago
no idea but incoming traffic doesnt matter
Brody
Brody9mo ago
No description
corgi mami
corgi mami9mo ago
doesn't incoming traffic wake an app from sleep?? so it would also cause it to not really stay asleep for long?
Brody
Brody9mo ago
you have a point
corgi mami
corgi mami9mo ago
or is it only http requests that wake it?
Brody
Brody9mo ago
im sure you can wake it other ways too
corgi mami
corgi mami9mo ago
this is also on the app sleeping page, so I guess it won't even work with private networking
No description
corgi mami
corgi mami9mo ago
which makes me wonder how people use it with public networking??
Brody
Brody9mo ago
thats worded really badly it should read "Private Networking does not current have support for waking other services when calling the private domain, the public networking domain must be used to wake the service"
corgi mami
corgi mami9mo ago
Ohhh I see
Brody
Brody9mo ago
aka not applicable to you at all its just when you want to wake service b from service a, you would need to call service b's public domain since it can't be woken from calling its private domain
corgi mami
corgi mami9mo ago
Okay that makes sense Thanks for all of your help! I'm glad the outbound traffic is down to 0 now, but I'm going to keep trying to figure out where this inbound traffic is coming from so hopefully I can get it down to 0 when nothing is in use and utilize app sleeping Please let me know if you have any direction as to what I should be looking into for this bc I'm still a little stumped, hopefully google will help lol
Brody
Brody9mo ago
the service in your screenshot, wouldn't it only cost 50 cents a month?
corgi mami
corgi mami9mo ago
it's the memory that's been driving the cost up for me, so that's why i want to utilize app sleeping
No description
corgi mami
corgi mami9mo ago
i have a few projects i want to utilize app sleeping on bc the memory costs add up between them
Brody
Brody9mo ago
fair enough
corgi mami
corgi mami9mo ago
No description
corgi mami
corgi mami9mo ago
The database still has these logs coming in even though I'm not actively doing anything This must be the incoming traffic still right?
Brody
Brody9mo ago
you can probably expand those logs I think mongo uses structured logging
corgi mami
corgi mami9mo ago
No description
corgi mami
corgi mami9mo ago
I'm looking at mongodb docs right now trying to figure it out
corgi mami
corgi mami9mo ago
No description
corgi mami
corgi mami9mo ago
this one just came through too
Brody
Brody9mo ago
that's a local ipv4 address meaning it's a connection from the public network but what your database is doing wouldn't prevent the app from sleeping
corgi mami
corgi mami9mo ago
Is it possible for that to still get through if i'm using private networking now??
Brody
Brody9mo ago
i dont think you have went and disabled the public network on the database, so yes
corgi mami
corgi mami9mo ago
Ohhh I thought I just had to switch the connection string I was using
Brody
Brody9mo ago
thats just how your app is connecting to the database
corgi mami
corgi mami9mo ago
ohhh i disabled public networking ont he database and I haven't received anymore logs but it's still showing inbound traffic hmmm could it somehow be flowing to the database from the inbound traffic showing on the server too??
Brody
Brody9mo ago
could it somehow be flowing to the database from the inbound traffic showing on the server too??
this question doesnt make much sense tbh, so im not sure how to answer it
corgi mami
corgi mami9mo ago
I also removed the public domain from the server just to see if the inbound traffic would stop, but it's still happening on both server and database
Brody
Brody9mo ago
that doesn’t necessarily cut off acesss
corgi mami
corgi mami9mo ago
Sorry for wording it poorly lol, I just meant like since there is inbound traffic on the server, which connects to the database, could that traffic on the server flow through to the database network usage too?? hmmm, yeah I'm a little lost on what to look at from here lol
Brody
Brody9mo ago
me too
corgi mami
corgi mami9mo ago
I wonder if more people will start having this issue as app sleeping becomes more popular My apps are pretty basic so I'm just struggling to understand how anybody gets app sleeping to work if even on basic apps like mine there is constant inbound traffic
Brody
Brody9mo ago
but like i said, theres really not much railway can do here, unless they decide to give the users a manual sleep and wake button
corgi mami
corgi mami9mo ago
Yeahhh, does railway not have more insightful data that would show where my network usage is coming from at least??
Brody
Brody9mo ago
they would have every kind of log imaginable, but thats not something they can just expose to the end user
macwilko
macwilko9mo ago
Just wondering, but what about using a cron task to remove the deployment during hours not used? Maybe it’s not dynamic like app sleeping, but if you know you’re not frequently using a service, you could schedule it to be awake for certain hours in the day?
corgi mami
corgi mami9mo ago
Yeah I have some backup options, but I was just really wanting to try to figure this out because it would be a nice feature to take advantage of, but I might have to move on and just remove deployments instead 😦 Thanks for the help guys!!
Another Menace
Another Menace9mo ago
sure ^_^ have you found the reason? did you solve it?
corgi mami
corgi mami9mo ago
Nooo, I still can't figure out where the inbound traffic is coming from so my apps won't go to sleep and stay asleep 😦
Another Menace
Another Menace9mo ago
Oh that's so bad
Brody
Brody9mo ago
quite off topic
Another Menace
Another Menace9mo ago
Oh let me delete it
Brody
Brody9mo ago
i would like to hear more about that though, please open a help thread, maybe with more information we could pinpoint a problem!
Another Menace
Another Menace9mo ago
sure ^_^ I'll create a new thread tomorrow and let you know
Want results from more Discord servers?
Add your server