Compare commits

...

3 Commits

Author SHA1 Message Date
Fangliding
56cd5643d8 fix 2024-12-27 02:16:02 +08:00
Fangliding
d0911cec88 Set a short timeout for dns 2024-12-27 02:12:05 +08:00
RPRX
2782f13279 Dokodemo TPROXY: Move "defer pw.Close()" into "responseDone()"
Fixes https://github.com/XTLS/Xray-core/issues/4194
2024-12-26 14:17:13 +00:00

View File

@@ -3,6 +3,7 @@ package dokodemo
import (
"context"
"sync/atomic"
"time"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
@@ -114,7 +115,14 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn st
plcy := d.policy()
ctx, cancel := context.WithCancel(ctx)
timer := signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
var timer *signal.ActivityTimer
// if dns req, set a short timeout value
if dest.Port == 53 {
timer = signal.CancelAfterInactivity(ctx, cancel, 10*time.Second)
} else {
timer = signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
}
if inbound != nil {
inbound.Timer = timer
@@ -180,7 +188,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 +226,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)
}