Skip to content

Conversation

@zenazn
Copy link

@zenazn zenazn commented Dec 29, 2025

Some infrastructure providers provide scale-to-zero support: the provider will automatically start your service just-in-time when a request arrives at a minor latency hit, and will stop your application if there are no in-flight connections. This helps save money, because you aren't billed for the time in which your application is idle.

This works best when the application cooperates, voluntarily exiting after a period of inactivity (especially for a proxy like sing-box which has long-lived persistent connections). This PR implements this cooperation for sing-box: it watches for traffic and keeps a last-activity timestamp. Every 10 seconds, it checks if there has been any activity in a configured timeout. If not, it calls os.Exit(0).

I've tested this out on my scale-to-zero platform of choice and it seems to work well! I'm seeing a substantial reduction in costs without much degradation in user experience using a timeout of 1m. Of course, sing-box behaves exactly as it previously did when this option is not enabled.

@nekohasekai nekohasekai force-pushed the dev-next branch 13 times, most recently from dfdd296 to 0a8b7a3 Compare January 2, 2026 11:23
@nekohasekai nekohasekai force-pushed the dev-next branch 8 times, most recently from 1bd617e to 0028b06 Compare January 12, 2026 12:44
@nekohasekai nekohasekai force-pushed the dev-next branch 6 times, most recently from 237887d to 5d67c13 Compare January 17, 2026 11:21
@zenazn
Copy link
Author

zenazn commented Jan 20, 2026

@nekohasekai is there any interest in merging this? It would be a big help for me, but I understand if it doesn't seem helpful enough for a more general audience. If you're not interested, I'll close this PR and maintain my own patches—please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant