Idle Rails app not sleeping

pauldps
HOBBY

a year ago

I deployed a Rails API recently with App Sleeping enabled, but the app is not sleeping after idling for hours. There's activity in Network metrics that I can't figure out where it's coming from, as the logs don't show anything other than old API requests.

Things I've tried:

  • Disabled public URL to prevent external access including bots. Doesn't seem to change anything in Network graph

  • Disabled database connection reaping in my database config (it was running every 10 seconds) but it doesn't seem to have fixed it. For context, the app connects to an external Postgres database (not on Railway). There's not anything else external such as Redis, it's only the database.

0 Replies

pauldps
HOBBY

a year ago

71754a48-09bb-4250-b361-ff5ab1df9597


pauldps
HOBBY

a year ago

Found a message that might explain the problem (edit: not sure)
https://discord.com/channels/713503345364697088/1210336429855473705/1210697666514915368
So since it connects to an external/public database it can't go to sleep, even without outbound traffic?


pauldps
HOBBY

a year ago

Also it seems it's only incoming traffic which should not matter for App Sleeping according to ➡️ https://discord.com/channels/713503345364697088/1210336429855473705/1210706235033391186

1236542462634229800


a year ago

there is outbound traffic though, looks at your graph very closely


a year ago

inbound traffic would tend to generate outbound as your app answers the request


pauldps
HOBBY

a year ago

ah ok, indeed there are tiny variations in the outbound traffic


pauldps
HOBBY

a year ago

I'm assuming the inbound traffic is coming from the database connection since the public URL is disabled


pauldps
HOBBY

a year ago

although I just noticed that in the same project I have another API, not in Rails but in Node/Bun, that connects to a database which is a libSQL private instance inside the project and is also not sleeping, would the same apply even if the db for that one is not external/public?


a year ago

private network traffic does not count towards inbound and outbound, in fact you can't even currently wake a service via the private network.


pauldps
HOBBY

a year ago

it must be something else then. The app in question is Node/Bun with these deps:

  "dependencies": {
    "@libsql/client": "0.5.6",
    "@paralleldrive/cuid2": "2.2.2",
    "bcrypt": "5.1.1",
    "drizzle-orm": "0.30.5",
    "elysia": "1.0.9",
    "jose": "5.2.3",
    "lodash": "4.17.21"
  },

perhaps something in there is doing telemetry or something


a year ago

that's also possible


pauldps
HOBBY

a year ago

something seems off. The Bun app was sleeping before (I think… I don't have evidence other than the huge gap in the graph below). After an unintentional restart there's constant network traffic:

1236817222618321000


pauldps
HOBBY

a year ago

It restarted because I mistakenly disabled Private Networking for the Rails app without knowing that it was a project-wide setting, so all my apps deployed when I changed it


pauldps
HOBBY

a year ago

I changed it back (reenabled Private Networking for the project) and it re-deployed a second time, which resulted in that constant Network activity. I'll let it run overnight to see if this behavior continues


pauldps
HOBBY

a year ago

Updated 30d Network graph from above

1237438147646980400


pauldps
HOBBY

a year ago

could this Network traffic be investigated? There were no changes in the app code-wise. This refers to the Bun app that connects to the libSQL database via private networking. Logs don't show incoming requests for the past 2 days or so, so I'm at a loss here.


pauldps
HOBBY

a year ago

I now know that the Rails app will never go to sleep due to connecting to an external database, but that shouldn't be the case for the Bun app I think.


a year ago

I'm sorry but this isn't something the team could help with


a year ago

the team is only able to provide hobby users support for billing or platform issues


pauldps
HOBBY

a year ago

Then help me understand this graph a bit better so I can investigate myself on correct data:

  • is private networking activity reported in that graph?

  • is Docker-level (OS/Kernel/etc) activity (anything outside of my app code) reported there as well?


a year ago

  1. no

  2. any traffic going outside and coming back of the private network is counted


pauldps
HOBBY

a year ago

so it's just real ingress/egress from my app? what if the Docker image for some reason uses an apt package that does telemetry for instance?


pauldps
HOBBY

a year ago

(I'm assuming it doesn't count)


a year ago

that would be counted, since that would be outbound traffic


pauldps
HOBBY

a year ago

got it. Would that affect the app's ability to sleep? Assuming yes


a year ago

yep, outbound traffic is what keeps the service awake


pauldps
HOBBY

a year ago

thanks for the answers. I'll try tweaking the Dockerfile as well as investigating traffic from the app, something like monkey-patching http.request in Node


pauldps
HOBBY

a year ago

feel free to close this (I don't know how)


Idle Rails app not sleeping - Railway Help Station