fix(group): prevent nil pointer panic in Selector on reconnect#3918
Open
kontsevoye wants to merge 1 commit intoSagerNet:stablefrom
Open
fix(group): prevent nil pointer panic in Selector on reconnect#3918kontsevoye wants to merge 1 commit intoSagerNet:stablefrom
kontsevoye wants to merge 1 commit intoSagerNet:stablefrom
Conversation
86c0e9f to
d091826
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds nil checks for
selected.Load()in Selector's connection methods to prevent nil pointer panic on reconnect.When a Tailscale endpoint uses a Selector as its detour, restarting sing-box causes a panic at
selector.go:144because the Tailscale endpoint dials through the Selector beforeStart()populates theselectedfield.Fixes #3917.
Changes
Added nil guards in 5 methods that call
s.selected.Load()without checking:DialContext— return errorListenPacket— return errorNewConnectionEx—CloseOnHandshakeFailureNewPacketConnectionEx—CloseOnHandshakeFailureNewDirectRouteConnection— return errorNote:
Network()andNow()already had nil checks — this makes the pattern consistent across all methods.Reproduction
Minimal config to reproduce (replace auth_key and server with valid values):
{ "dns": { "servers": [ { "type": "https", "tag": "proxy-dns", "detour": "proxy", "server": "1.1.1.1" }, { "type": "tailscale", "tag": "ts-dns", "endpoint": "tailscale" } ], "rules": [ { "domain_suffix": [ "ts.net" ], "server": "ts-dns" } ], "strategy": "ipv4_only", "final": "proxy-dns" }, "inbounds": [ { "type": "tun", "tag": "tun-in", "address": [ "172.19.0.1/30" ], "auto_route": true, "route_address": [ "100.64.0.0/10" ], "route_exclude_address": [ "1.2.3.4/32" ] } ], "endpoints": [ { "type": "tailscale", "tag": "tailscale", "detour": "proxy", "state_directory": "tailscale", "auth_key": "tskey-auth-VALID_KEY", "hostname": "test", "accept_routes": true, "udp_timeout": "5m0s" } ], "outbounds": [ { "type": "selector", "tag": "proxy", "outbounds": [ "vless-out" ], "default": "vless-out" }, { "type": "vless", "tag": "vless-out", "server": "1.2.3.4", "server_port": 8443, "uuid": "valid-uuid", "flow": "xtls-rprx-vision", "tls": { "enabled": true, "server_name": "example.com", "utls": { "enabled": true, "fingerprint": "chrome" }, "reality": { "enabled": true, "public_key": "valid", "short_id": "valid" } } }, { "type": "direct", "tag": "direct" } ], "route": { "default_domain_resolver": "proxy-dns", "rules": [ { "action": "sniff" }, { "protocol": "dns", "action": "hijack-dns" }, { "ip_cidr": [ "1.2.3.4/32" ], "outbound": "direct" }, { "ip_cidr": [ "100.64.0.0/10" ], "outbound": "tailscale" } ], "final": "proxy" } }Testing
sing-box runafter Ctrl+C