From 2782f13279c43c7f7881d776776d15a4f69970fa Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:17:13 +0000 Subject: [PATCH] Dokodemo TPROXY: Move "defer pw.Close()" into "responseDone()" Fixes https://github.com/XTLS/Xray-core/issues/4194 --- proxy/dokodemo/dokodemo.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index bbeab18ff621..d5d7480b9875 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -180,7 +180,6 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st return err } writer = NewPacketWriter(pConn, &dest, mark, back) - defer writer.(*PacketWriter).Close() /* sockopt := &internet.SocketConfig{ Tproxy: internet.SocketConfig_TProxy, @@ -219,6 +218,10 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st responseDone := func() error { defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) + if pw, ok := writer.(*PacketWriter); ok { + defer pw.Close() + } + if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil { return errors.New("failed to transport response").Base(err) }