diff -ruN a/app/dispatcher/default.go b/app/dispatcher/default.go --- a/app/dispatcher/default.go 2026-11-09 20:03:45 +++ b/app/dispatcher/default.go 2026-11-09 20:04:25 @@ -376,7 +376,10 @@ } func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, network net.Network) (SniffResult, error) { - payload := buf.NewWithSize(32767) + // RayRay patch: 8 KB instead of 32 KB, it is held by every new connection while sniffing, and a burst of them is + // when an iOS network extension is closest to its memory limit. A TLS ClientHello or the QUIC Initial packets that + // carry one, post-quantum key share included, are about 2 KB; the rest of the data waits in the cache unsniffed. + payload := buf.NewWithSize(8192) defer payload.Release() sniffer := NewSniffer(ctx) diff -ruN a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go --- a/app/proxyman/outbound/handler.go 2026-11-09 20:03:45 +++ b/app/proxyman/outbound/handler.go 2026-11-09 20:04:25 @@ -122,7 +122,9 @@ if config.Concurrency < 0 { h.mux = &mux.ClientManager{Enabled: false} } - if config.Concurrency >= 0 && config.Concurrency <= 128 { + // RayRay patch: only an unset value takes the default. Upstream's 0...128 here would turn every position + // of the app's stepper (1...128) into 128, so what the user chose would not be what runs. + if config.Concurrency == 0 { config.Concurrency = 128 } if config.Concurrency > 0 { diff -ruN a/infra/conf/transport_security.go b/infra/conf/transport_security.go --- a/infra/conf/transport_security.go 2026-11-09 20:03:45 +++ b/infra/conf/transport_security.go 2026-11-09 20:04:25 @@ -218,7 +218,11 @@ return nil, errors.New(`invalid "spiderX": `, c.SpiderX) } config.SpiderY = make([]int64, 10) - u, _ := url.Parse(c.SpiderX) + // RayRay patch: url.Parse gives nil for a bad escape such as "/%zz", and u.Query would end the app. + u, err := url.Parse(c.SpiderX) + if err != nil { + return nil, errors.New(`invalid "spiderX": `, c.SpiderX) + } q := u.Query() parse := func(param string, index int) { if q.Get(param) != "" { diff -ruN a/infra/conf/vless.go b/infra/conf/vless.go --- a/infra/conf/vless.go 2026-11-09 20:03:45 +++ b/infra/conf/vless.go 2026-11-09 20:04:25 @@ -364,6 +364,11 @@ return false } } + // RayRay patch: a value of padding segments only, with no key after them, would slice past its end below + // and a provider's link would end the app. Checked before anything is cut, so a tail of "none" is refused too. + if padding >= len(account.Encryption)-27-len(s[2]) { + return false + } account.Encryption = account.Encryption[27+len(s[2]):] if padding > 0 { account.Padding = account.Encryption[:padding-1] diff -ruN a/transport/internet/grpc/dial.go b/transport/internet/grpc/dial.go --- a/transport/internet/grpc/dial.go 2026-11-09 20:03:45 +++ b/transport/internet/grpc/dial.go 2026-11-09 20:04:25 @@ -48,6 +48,27 @@ globalDialerAccess sync.Mutex ) +// ResetDialers closes every cached gRPC client and forgets it. +// RayRay patch: the cache is global and keyed by each config's stream settings, so an Xray that is stopped and started +// again in the same process (a network change, a server switch) would leave its clients and their goroutines behind for +// good. The map is swapped at once, so that a client made after this call by the next Xray is not touched; the old ones +// are closed apart, Close can wait on a dead network. A dial still under way when the map is reset finds it nil, which +// getGrpcClient starts over from, or gets a closed client and returns its error. +func ResetDialers() { + globalDialerAccess.Lock() + clients := globalDialerMap + globalDialerMap = nil + globalDialerAccess.Unlock() + go func() { + for _, client := range clients { + // grpc.NewClient's error leaves a nil client in the map. + if client != nil { + _ = client.Close() + } + } + }() +} + func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (net.Conn, error) { grpcSettings := streamSettings.ProtocolSettings.(*Config) diff -ruN a/transport/internet/splithttp/client.go b/transport/internet/splithttp/client.go --- a/transport/internet/splithttp/client.go 2026-11-09 20:03:45 +++ b/transport/internet/splithttp/client.go 2026-11-09 20:04:25 @@ -183,6 +183,9 @@ transport := c.client.Transport if h3Transport, ok := transport.(*http3.Transport); ok { h3Transport.Close() + } else { + // RayRay patch: this client is retired, and an idle connection of it would stay for ConnIdleTimeout (5 minutes). + c.client.CloseIdleConnections() } return nil } diff -ruN a/transport/internet/splithttp/dialer.go b/transport/internet/splithttp/dialer.go --- a/transport/internet/splithttp/dialer.go 2026-11-09 20:03:45 +++ b/transport/internet/splithttp/dialer.go 2026-11-09 20:04:25 @@ -44,6 +44,24 @@ globalDialerAccess sync.Mutex ) +// ResetDialers retires every cached XMUX client and forgets the managers. +// RayRay patch: see grpc.ResetDialers. A client with requests still running is closed by DoneRunning, when the last one +// ends. The managers' slices are read under globalDialerAccess only, and no one can reach them once the map is swapped. +func ResetDialers() { + globalDialerAccess.Lock() + managers := globalDialerMap + globalDialerMap = nil + globalDialerAccess.Unlock() + go func() { + for _, manager := range managers { + for _, xmuxClient := range manager.xmuxClients { + xmuxClient.NotUsed.Store(true) + xmuxClient.maybeClose() + } + } + }() +} + func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (DialerClient, *XmuxClient) { realityConfig := reality.ConfigFromStreamSettings(streamSettings)