Skip to content

fix(ss2022): accept netproxy.Conn underlay for UDP to support proxy chaining - #5

Open
zhaob1n wants to merge 1 commit into
olicesx:perf/complete-optimizationsfrom
zhaob1n:fix/ss2022-udp-chain-panic
Open

zhaob1n wants to merge 1 commit into
olicesx:perf/complete-optimizationsfrom
zhaob1n:fix/ss2022-udp-chain-panic

Conversation

@zhaob1n

@zhaob1n zhaob1n commented Sep 19, 2026

Copy link
Copy Markdown

Problem

When shadowsocks_2022 is used as a downstream hop in a proxy chain (encountered in practice when running dae with chained-proxy nodes containing SS2022), UDP dialing triggers a runtime panic:

panic: interface conversion: *shadowsocks_2022.FakeNetPacketConn is not net.Conn: missing method LocalAddr

In ListenPacket, parentDialer.DialContext(...) returns a netproxy.Conn. For chained transports, the underlying connection satisfies netproxy.Conn but does not necessarily implement standard library net.Conn (LocalAddr / RemoteAddr). The unchecked type assertion conn.(net.Conn) panics.

Solution

  1. Accept netproxy.Conn for UDP underlays: UdpConn only requires Read, Write, Close, and deadline controls from the underlying transport—it does not rely on LocalAddr or RemoteAddr. Changed UdpConn to embed netproxy.Conn and updated constructors accordingly.
  2. Safe ListenPacket: Passed the netproxy.Conn directly without the unsafe net.Conn assertion.
  3. Address method forwarding: Added LocalAddr() and RemoteAddr() to both UdpConn and FakeNetPacketConn to forward inner transport addresses (or resolve the target address on FakeNetPacketConn), ensuring they satisfy net.Conn for any external callers asserting it.
  4. Regression tests: Added tests covering chained dialers with bare netproxy.Conn underlays and nested shadowsocks_2022 instances.

…haining

In chained proxy scenarios where shadowsocks_2022 is preceded by another
proxy (or another shadowsocks_2022 instance), parentDialer.DialContext
returns a netproxy.Conn (such as FakeNetPacketConn or other protocol UDP
wrappers) that does not implement standard library net.Conn.

Previously, ListenPacket performed an unchecked type assertion
conn.(net.Conn), causing a runtime panic:
  interface conversion: *FakeNetPacketConn is not net.Conn: missing method LocalAddr

Changes:
- UdpConn: embed netproxy.Conn instead of net.Conn (UdpConn only invokes
  Read/Write/Close and deadline controls from the underlay).
- NewUdpConn / NewUdpConnWithContext: accept netproxy.Conn directly.
- ListenPacket: pass the netproxy.Conn returned by parentDialer without
  an unsafe type assertion to net.Conn.
- UdpConn & FakeNetPacketConn: add LocalAddr() and RemoteAddr() forwarding
  methods so they continue to satisfy net.Conn for any external consumer
  that asserts it.
- dialer_test: add regression tests for chained UDP underlays backed by
  bare netproxy.Conn and chained shadowsocks_2022 dialers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant