From dd74780d4e1cea475b450715268d7c38d28dd014 Mon Sep 17 00:00:00 2001 From: lovitus Date: Wed, 25 Nov 2026 09:04:24 +0800 Subject: [PATCH] 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. --- adapter/parser.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adapter/parser.go b/adapter/parser.go index 68bccdbf..065bcc27 100644 --- a/adapter/parser.go +++ b/adapter/parser.go @@ -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 } }