fix: close the outbound when smux options are invalid (#3517)

ParseProxy built the outbound and then returned early if the smux options
failed to decode or NewSingMux failed, without closing it. Outbounds that
acquire process-wide state in their constructor kept it: EasyTier and
Tailscale register a DNS client by name and only remove it in Close, so a
failed parse left a client behind that a later outbound of the same name
would replace and then delete.

Close the outbound on both error paths and keep the wrapped value in a
separate variable so a failed NewSingMux cannot shadow the proxy that needs
closing.
This commit is contained in:
lovitus authored and GitHub committed 2026-11-25 09:04:24 +08:00
1 parent c7af25cee0
commit dd74780d4e
1 file changed
+5 -3
+5 -3
View File
@@ -233,15 +233,17 @@ func ParseProxy(mapping map[string]any, options ...ProxyOption) (C.Proxy, error)
if muxMapping, muxExist := mapping["smux"].(map[string]any); muxExist {
muxOption := &outbound.SingMuxOption{}
err = decoder.Decode(muxMapping, muxOption)
if err != nil {
if err := decoder.Decode(muxMapping, muxOption); err != nil {
_ = proxy.Close()
return nil, err
}
if muxOption.Enabled {
proxy, err = outbound.NewSingMux(*muxOption, proxy)
wrapped, err := outbound.NewSingMux(*muxOption, proxy)
if err != nil {
_ = proxy.Close()
return nil, err
}
proxy = wrapped
}
}