TUN inbound: Avoid panic on nil RemoteAddr due to quickly closed connection (#6365)

Fixes https://github.com/XTLS/Xray-core/issues/6364#issuecomment-4778262075

---------

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
风扇滑翔翼 2026-06-23 19:37:21 +08:00 • committed by GitHub
parent fab4bcc1ed
commit e7e9254630
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,7 +143,14 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) {
defer cancel()
ctx = c.ContextWithID(ctx, session.NewID())
source := net.DestinationFromAddr(conn.RemoteAddr())
// if the connection is already closed, conn.RemoteAddr() will be nil
// due to gvisor weird behavior
remote := conn.RemoteAddr()
if remote == nil {
errors.LogInfo(t.ctx, "dropped quickly closed connection")
return
}
source := net.DestinationFromAddr(remote)
inbound := session.Inbound{
Name: "tun",
Tag: t.tag,