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 11 times, most recently from 55812c6 to c590569 Compare January 1, 2026 09:59
Zephyruso and others added 19 commits January 2, 2026 19:19
We mistakenly believed that `libresolv`'s `search` function worked correctly in NetworkExtension, but it seems only `getaddrinfo` does.

This commit changes the behavior of the `local` DNS server in NetworkExtension to prefer DHCP, falling back to `getaddrinfo` if DHCP servers are unavailable.

It's worth noting that `prefer_go` does not disable DHCP since it respects Dial Fields, but `getaddrinfo` does the opposite. The new behavior only applies to NetworkExtension, not to all scenarios (primarily command-line binaries) as it did previously.

In addition, this commit also improves the DHCP DNS server to use the same robust query logic as `local`.
We do not have the `com.apple.developer.networking.multicast` entitlement and are unable to obtain it for non-technical reasons.
@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 3 times, most recently from 1a353ba to 5ae7436 Compare January 16, 2026 22:15
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.

5 participants