Skip to content

Commit 70739bc

Browse files
🚮 Drop TCP timeout and unnecessary SetKeepAlive (#29)
I checked Go's source code. Both the TCP listener and dialer sets a 15s keepalive by default. So it's unnecessary to set it in mmp-go. And since we already have TCP keepalive, the timeout is totally unnecessary, and it breaks long connections even if the connection is actively transmitting data.
1 parent 51a94d2 commit 70739bc

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

dispatcher/tcp/tcp.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ package tcp
33
import (
44
"errors"
55
"fmt"
6-
"github.com/Qv2ray/mmp-go/cipher"
7-
"github.com/Qv2ray/mmp-go/config"
8-
"github.com/Qv2ray/mmp-go/dispatcher"
9-
"github.com/Qv2ray/mmp-go/infra/pool"
106
"io"
117
"log"
128
"net"
139
"sync"
1410
"time"
11+
12+
"github.com/Qv2ray/mmp-go/cipher"
13+
"github.com/Qv2ray/mmp-go/config"
14+
"github.com/Qv2ray/mmp-go/dispatcher"
15+
"github.com/Qv2ray/mmp-go/infra/pool"
1516
)
1617

1718
//[salt][encrypted payload length][length tag][encrypted payload][payload tag]
1819
const (
19-
DefaultTimeout = 7440 * time.Second
20-
BasicLen = 32 + 2 + 16
20+
BasicLen = 32 + 2 + 16
2121
)
2222

2323
func init() {
@@ -79,7 +79,6 @@ func (d *TCP) handleConn(conn net.Conn) error {
7979
userContext *config.UserContext
8080
)
8181
defer conn.Close()
82-
_ = conn.(*net.TCPConn).SetKeepAlive(true)
8382

8483
var data = pool.Get(BasicLen)
8584
defer pool.Put(data)
@@ -110,9 +109,7 @@ func (d *TCP) handleConn(conn net.Conn) error {
110109
if err != nil {
111110
return fmt.Errorf("[tcp] %s <-> %s <-x-> %s handleConn dial error: %w", conn.RemoteAddr(), conn.LocalAddr(), server.Target, err)
112111
}
113-
_ = rc.(*net.TCPConn).SetKeepAlive(true)
114112

115-
_ = rc.SetDeadline(time.Now().Add(DefaultTimeout))
116113
_, err = rc.Write(data[:n])
117114
if err != nil {
118115
return fmt.Errorf("[tcp] %s <-> %s <-x-> %s handleConn write error: %w", conn.RemoteAddr(), conn.LocalAddr(), server.Target, err)

0 commit comments

Comments
 (0)