Skip to content

Add inactivity timeout support#3655

Closed
zenazn wants to merge 1 commit intoSagerNet:dev-nextfrom
zenazn:carl-timeout
Closed

Add inactivity timeout support#3655
zenazn wants to merge 1 commit intoSagerNet:dev-nextfrom
zenazn:carl-timeout

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
@nekohasekai nekohasekai force-pushed the dev-next branch 23 times, most recently from 07c65a7 to 1befbfc Compare February 27, 2026 11:55
@nekohasekai nekohasekai force-pushed the dev-next branch 7 times, most recently from 98e21fc to 9c63f44 Compare March 3, 2026 13:21
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.

2 participants