Skip to content

Commit 4330aef

Browse files
authored
feat: enhance cancellation handling by setting read deadlines for tunnel connections
1 parent 49eb975 commit 4330aef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/common.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,16 @@ func (c *Common) commonTCPLoop() {
719719
// 注册取消函数
720720
c.cancelMap.Store(id, func() {
721721
if targetConn != nil {
722-
targetConn.Close()
722+
targetConn.SetReadDeadline(time.Now())
723+
}
724+
if remoteConn != nil {
725+
remoteConn.SetReadDeadline(time.Now())
723726
}
724727
})
725728
defer c.cancelMap.Delete(id)
726729

727730
defer func() {
731+
remoteConn.SetReadDeadline(time.Time{})
728732
c.tunnelPool.Put(id, remoteConn)
729733
c.logger.Debug("Tunnel connection: put %v -> pool active %v", id, c.tunnelPool.Active())
730734

@@ -1039,6 +1043,7 @@ func (c *Common) commonTCPOnce(signalURL *url.URL) {
10391043
c.logger.Debug("Tunnel connection: get %v <- pool active %v", id, c.tunnelPool.Active())
10401044

10411045
defer func() {
1046+
remoteConn.SetReadDeadline(time.Time{})
10421047
c.tunnelPool.Put(id, remoteConn)
10431048
c.logger.Debug("Tunnel connection: put %v -> pool active %v", id, c.tunnelPool.Active())
10441049

@@ -1079,7 +1084,10 @@ func (c *Common) commonTCPOnce(signalURL *url.URL) {
10791084
// 注册取消函数
10801085
c.cancelMap.Store(id, func() {
10811086
if targetConn != nil {
1082-
targetConn.Close()
1087+
targetConn.SetReadDeadline(time.Now())
1088+
}
1089+
if remoteConn != nil {
1090+
remoteConn.SetReadDeadline(time.Now())
10831091
}
10841092
})
10851093
defer c.cancelMap.Delete(id)

0 commit comments

Comments
 (0)