Skip to content

Commit

Permalink
fix a race condition issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Jul 20, 2023
1 parent 90861b6 commit dbc5ee9
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Release.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
### Features
### Fixes

* Fix the issue of not disabling tcp keepalive when configuring `tcp_keepalive` = -1 in frps.
* Fix a race condition error.
4 changes: 3 additions & 1 deletion client/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
}
}
if baseConfig.UseCompression {
remote = libio.WithCompression(remote)
var releaseFn func()
remote, releaseFn = libio.WithCompressionFromPool(remote)
defer releaseFn()
}

// check if we need to send proxy protocol info
Expand Down
4 changes: 3 additions & 1 deletion client/proxy/sudp.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
}
}
if pxy.cfg.UseCompression {
rwc = libio.WithCompression(rwc)
var releaseFn func()
rwc, releaseFn = libio.WithCompressionFromPool(rwc)
defer releaseFn()
}
conn = utilnet.WrapReadWriteCloserToConn(rwc, conn)

Expand Down
4 changes: 3 additions & 1 deletion client/proxy/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
}
}
if pxy.cfg.UseCompression {
rwc = libio.WithCompression(rwc)
var releaseFn func()
rwc, releaseFn = libio.WithCompressionFromPool(rwc)
defer releaseFn()
}
conn = utilnet.WrapReadWriteCloserToConn(rwc, conn)

Expand Down
4 changes: 3 additions & 1 deletion client/visitor/stcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func (sv *STCPVisitor) handleConn(userConn net.Conn) {
}

if sv.cfg.UseCompression {
remote = libio.WithCompression(remote)
var releaseFn func()
remote, releaseFn = libio.WithCompressionFromPool(remote)
defer releaseFn()
}

libio.Join(userConn, remote)
Expand Down
4 changes: 3 additions & 1 deletion client/visitor/xtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
}
}
if sv.cfg.UseCompression {
muxConnRWCloser = libio.WithCompression(muxConnRWCloser)
var releaseFn func()
muxConnRWCloser, releaseFn = libio.WithCompressionFromPool(muxConnRWCloser)
defer releaseFn()
}

_, _, errs := libio.Join(userConn, muxConnRWCloser)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/coreos/go-oidc/v3 v3.4.0
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb
github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373
github.com/fatedier/golib v0.1.1-0.20230720124328-204db2e322f8
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible
github.com/go-playground/validator/v10 v10.11.0
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -43,7 +43,7 @@ require (
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb h1:wCrNShQidLmvVWn/0PikGmpdP0vtQmnvyRg3ZBEhczw=
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb/go.mod h1:wx3gB6dbIfBRcucp94PI9Bt3I0F2c/MyNEWuhzpWiwk=
github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373 h1:lprMgD5nOD9k2Af0T/al8nU31YvFkTyCtRapi4z2jbQ=
github.com/fatedier/golib v0.1.1-0.20230717092310-8d13bff6d373/go.mod h1:Wdn1pJ0dHB1lah6FPYwt4AO9NEmWI0OzW13dpzC9g4E=
github.com/fatedier/golib v0.1.1-0.20230720124328-204db2e322f8 h1:8JYzwZ26k1zEsjgits6GHsQxm2tl3K3FYgMMLcIKBKU=
github.com/fatedier/golib v0.1.1-0.20230720124328-204db2e322f8/go.mod h1:Lmi9U4VfvdRvonSMh1FgXVy1hCXycVyJk4E9ktokknE=
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible h1:ssXat9YXFvigNge/IkkZvFMn8yeYKFX+uI6wn2mLJ74=
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible/go.mod h1:YpCOaxj7vvMThhIQ9AfTOPW2sfztQR5WDfs7AflSy4s=
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=
Expand Down Expand Up @@ -189,8 +189,9 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strings"
)

var version = "0.51.0"
var version = "0.51.1"

func Full() string {
return version
Expand Down
4 changes: 3 additions & 1 deletion server/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err err
}
}
if pxy.cfg.UseCompression {
rwc = libio.WithCompression(rwc)
var releaseFn func()
rwc, releaseFn = libio.WithCompressionFromPool(rwc)
defer releaseFn()
}

if pxy.GetLimiter() != nil {
Expand Down
4 changes: 3 additions & 1 deletion server/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) {
}
}
if cfg.UseCompression {
local = libio.WithCompression(local)
var releaseFn func()
local, releaseFn = libio.WithCompressionFromPool(local)
defer releaseFn()
}

if pxy.GetLimiter() != nil {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ var _ = ginkgo.Describe("[Feature: Basic]", func() {
case "xtcp":
localPortName = framework.TCPEchoServerPort
protocol = "tcp"
ginkgo.Skip("stun server is not stable")
}

correctSK := "abc"
Expand Down Expand Up @@ -363,6 +364,7 @@ var _ = ginkgo.Describe("[Feature: Basic]", func() {
use_encryption = true
use_compression = true
`,
skipXTCP: true,
},
{
proxyName: "with-error-sk",
Expand Down

0 comments on commit dbc5ee9

Please sign in to comment.