9 months ago
I have a hasura gql service that connects to postgresql service, both have serverless option turned on but none of them goes to sleep
On the metrics tab on the hasura service, I can see a periodic ingress activity (every 5m or 10m) of about 293 bytes
When I ssh into it and ran sstrace, I found out that hasura keeps an active connection to postgres
Is that the intended behavior that active connections between 2 service on private network prevents them from sleeping?
sstrace logs (connect and accept):
[pid 1279] 09:51:09 connect(201, {sa_family=AF_INET6, sin6_port=htons(53), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "fd12::10", &sin6_addr), sin6_scope_id=0}, 28) = 0
[pid 1279] 09:51:09 connect(201, {sa_family=AF_INET6, sin6_port=htons(5432), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "<resolved-ipv6>", &sin6_addr), sin6_scope_id=0}, 28) = -1 EINPROGRESS (Operation now in progress)
strace: Process 1286 attached
[pid 1284] 09:52:30 connect(202, {sa_family=AF_INET6, sin6_port=htons(53), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "fd12::10", &sin6_addr), sin6_scope_id=0}, 28) = 0
[pid 1284] 09:52:30 connect(202, {sa_family=AF_INET6, sin6_port=htons(5432), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "<resolved-ipv6>", &sin6_addr), sin6_scope_id=0}, 28) = -1 EINPROGRESS (Operation now in progress)
[pid 1283] 10:02:30 connect(201, {sa_family=AF_INET6, sin6_port=htons(53), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "fd12::10", &sin6_addr), sin6_scope_id=0}, 28) = 0
[pid 1283] 10:02:30 connect(201, {sa_family=AF_INET6, sin6_port=htons(5432), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "<resolved-ipv6>", &sin6_addr), sin6_scope_id=0}, 28) = -1 EINPROGRESS (Operation now in progress)
Pinned Solution
9 months ago
I have read again you have active connections so the service is naturally not going to sleep because the network is being used actively
6 Replies
9 months ago
My understanding of the documentation is if you have sleeping enabled this should have worked https://docs.railway.com/reference/app-sleeping
9 months ago
I have read again you have active connections so the service is naturally not going to sleep because the network is being used actively
9 months ago
Oh, last time I checked I didn't see database connections being mentioned (was probably a while ago)
9 months ago
Yes, this is expected behavior.
An active or periodically attempted connection between Hasura and PostgreSQL — even on a private network — prevents serverless services from sleeping. Hasura maintains or retries database connections to keep the pool alive, which causes periodic ingress activity (like the ~293 bytes every 5–10 mins you observed). This network activity keeps both services awake.
9 months ago
Yes, this is expected behavior.
Hasura maintains a persistent connection to PostgreSQL to support its metadata engine, live queries, and subscriptions, even when there's no active client traffic. This connection is kept alive by default to reduce latency and avoid the overhead of reconnecting on every new request.
When both services are in serverless mode and connected over a private network, this persistent connection qualifies as "activity." Therefore, it prevents either service from entering sleep mode, since Railway interprets internal traffic (such as a TCP connection from Hasura to Postgres) as active usage.
If you'd like both services to go idle, you'd need to terminate persistent connections when inactive — but this is not recommended for Hasura production workloads, as it will increase response latency and may break live features.
Let me know if you want help modifying the connection behavior, but again — it's generally not advisable.
Status changed to Solved chandrika • 9 months ago