r/webdev • u/v0id_user • Oct 17 '26
Showoff Saturday Minecraft servers that sleep when empty and wake when someone joins. Holding a TCP login open for 45 seconds without the client giving up
I built a Minecraft server host where every server sleeps when nobody plays, and wakes when a friend joins. The hard part was the join itself, so here's how that works.
The problem
A sleeping server suspended on Fly resumes in about 2 s. But one that has to boot (first start, after a change, or once the snapshot is gone) takes 40 to 50 s. The Minecraft client
gives up on a connection that says nothing for 30 s.
The trick
Every connection lands on an edge proxy first. If the server is asleep, the edge holds the login open and keeps it alive by sending a login query every few seconds. Every client since 1.13 answers it, which counts as the server talking. The edge keeps those answers to itself, buffers everything else the client sent, and replays it to the server once it's up, as if the player had just dialled in.
Other bits
- The server list shows a sleeping server's own message plus a grey "sleeping" line, cut to fit the list's 305px row by measuring the default font's glyph widths.
- A ping from the server list can wake a server early, asked once per network so random scanners don't keep waking things.
- Routes change one hostname at a time through mc-router's API, because reloading its routes file drops players who arrive mid-reload.
- Floods are refused per server at the edge, so one busy server doesn't slow every other server's joins.
It's open source (TypeScript, AGPL):
github.com/cubepals/cubepals (the edge is apps/edge)
Happy to go deeper on any of it.
12
u/CardinalHijack Oct 18 '26
Does this work with pumpkin? (https://pumpkinmc.org/)
15
u/SawToothKernel Oct 18 '26
You could try the same with a Durable Object. They do the same thing with WebSockets, and can wake in milliseconds.
32
u/UnacceptableUse Oct 18 '26
Don't modern Minecraft versions automatically pause the server after x minutes of inactivity?
13
u/zaxwebs Oct 18 '26
Always good to come around these solutions. I'm building a game as a side-project so happy to see some activity in the space.
3
u/iPhoneK1LLA Oct 18 '26
I'm not aware of the tech, but doesn't AMP by CubeCoders do something similar?
3
u/Far-Inevitable6386 Oct 18 '26
Out of curiosity, what happens if the server fails to boot after the 45 s? Does the edge drop the player with a message, or retry?
4
u/saltyourhash Oct 18 '26
Great idea
2
u/quietcodelife Oct 18 '26
the proxy replay approach is smart. basically mitm-ing your own boot process so the client never knows something went wrong.
curious whether you hit any issues with connection limits on the edge when a bunch of people try to join at once and theyre all being held. or is fly's network layer handling that gracefully?
1
u/shelfbreak Oct 18 '26
Interesting, good idea with the proxy
1
u/Andromeda_Ascendant Laravel & InertiaJS Oct 18 '26 edited Oct 18 '26
Looks like a fun project, and I like the name!
I did notice one little quirk with the /admin pages, where the UI briefly renders before showing a message that it's for admins only. Not the most serious problem but if it was me I'd fix that.
Edit:
Another thing, it seems like server-side plugins are mistakenly included in the client-side "you need to have these" for the server listings. https://cubepals.com/server/arcade i.e. Take ChatSentinel, from my understanding it's a server plugin and has nothing to do with the player needing it.
1
u/geoffreybyers Oct 20 '26
The client timeout is the only constraint that matters. The proxy has to be a stateful buffer, not a keep-alive sender. Most people build the latter and get the wake-up wrong.
1
u/chaos50006 Oct 20 '26
There's been aws terraform for this for at least a couple of years already. I used it
0
u/[deleted] Oct 18 '26
[deleted] — view deleted comment
21
u/[deleted] Oct 17 '26
[removed] — view removed comment