sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

Feature request: Resilient remote rule-set initialization to prevent startup failure

Open Pushkinmazila2 opened this issue 7 months ago • 1 comments

Is your feature request related to a problem? Please describe.

Currently, sing-box fails to start if a remote rule-set is defined but cannot be fetched during initialization (e.g., on a "cold start" where no local path exists yet). This creates a "chicken and egg" problem (circular dependency):

  1. The core needs rule-sets to route traffic correctly.
  2. To download these rule-sets via download_detour, a functional outbound/proxy is often required.
  3. If the download fails (due to network issues or proxy not being ready), the entire core fails to start, preventing the very connection needed to fetch the rules.

Describe the solution you'd like

I would like to propose two possible scenarios to resolve this:

Scenario 1: Criticality Flag (critical: false)

Add an optional critical boolean field to the rule-set configuration (defaulting to true for backward compatibility).

  • If critical: false and the rule-set fails to load/download at startup, sing-box should initialize it as an "empty" set, log a warning, and continue starting the core.
  • The rule-set should then be updated in the background as soon as the network/proxy becomes available.

Scenario 2: Staged/Phase-based Startup

Implement a more sophisticated initialization sequence:

  1. Phase 1: Network & Outbounds. Initialize the networking stack and outbounds (especially those used in download_detour).
  2. Phase 2: Resource Fetching. Fetch remote rule-sets. During this phase, incoming traffic from inbounds can be queued or dropped to prevent leaks.
  3. Phase 3: Full Operation. Once rules are loaded, open the inbounds for user traffic.

Describe alternatives you've considered

  • Manual Provisioning: Manually downloading .srs files via curl before starting sing-box. This is difficult to manage on embedded systems (routers) or mobile devices.
  • Direct Detour: Setting download_detour to direct. This fails if the rule-set source (e.g., GitHub) is blocked by the local ISP(gov)/firewall.

Additional context

This change would significantly improve the user experience for:

  • New installations (provisioning nodes without pre-shipped cache).
  • Unreliable network environments where a cold boot might happen without an active internet connection.
  • Users who rely on complex routing rules that require external lists to function.

Pushkinmazila2 avatar Apr 22 '26 19:04 Pushkinmazila2

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jun 22 '26 02:06 github-actions[bot]