From cd4ce973e9f6ef3a7acf9a7030927b4143f9ea47 Mon Sep 17 00:00:00 2001 From: pexcn Date: Tue, 1 Sep 2026 12:57:10 +0800 Subject: [PATCH] WebSocket client: Avoid panic before real dialing in delayDialConn (#6544) Fixes https://github.com/teddysun/xray-plugin-android/issues/11 --- transport/internet/websocket/dialer.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/transport/internet/websocket/dialer.go b/transport/internet/websocket/dialer.go index 8e295da06..199514a5c 100644 --- a/transport/internet/websocket/dialer.go +++ b/transport/internet/websocket/dialer.go @@ -175,6 +175,25 @@ type delayDialConn struct { streamSettings *internet.MemoryStreamConfig } +// LocalAddr returns nil until the deferred WebSocket dial has completed. +// Without this method, Go promotes LocalAddr from the embedded net.Conn; the +// embedded interface is nil before the first Write, so the promoted call panics. +func (d *delayDialConn) LocalAddr() net.Addr { + if d.Conn == nil { + return nil + } + return d.Conn.LocalAddr() +} + +// RemoteAddr returns nil until the deferred WebSocket dial has completed. +// See LocalAddr for why an explicit method is required here. +func (d *delayDialConn) RemoteAddr() net.Addr { + if d.Conn == nil { + return nil + } + return d.Conn.RemoteAddr() +} + func (d *delayDialConn) Write(b []byte) (int, error) { if d.closed { return 0, io.ErrClosedPipe