Compare commits

..

1 Commits

Author SHA1 Message Date
fatedier
22154c22cb frpc: support metadatas and annotations in frpc proxy commands 2025-01-06 14:15:50 +08:00
10 changed files with 15 additions and 67 deletions

View File

@ -1,7 +1,3 @@
### Features
* Support metadatas and annotations in frpc proxy commands.
### Fixes
* Properly release resources in service.Close() to prevent resource leaks when used as a library.

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.0
require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/coreos/go-oidc/v3 v3.10.0
github.com/fatedier/golib v0.5.1
github.com/fatedier/golib v0.5.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.0

4
go.sum
View File

@ -21,8 +21,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatedier/golib v0.5.1 h1:hcKAnaw5mdI/1KWRGejxR+i1Hn/NvbY5UsMKDr7o13M=
github.com/fatedier/golib v0.5.1/go.mod h1:W6kIYkIFxHsTzbgqg5piCxIiDo4LzwgTY6R5W8l9NFQ=
github.com/fatedier/golib v0.5.0 h1:hNcH7hgfIFqVWbP+YojCCAj4eO94pPf4dEF8lmq2jWs=
github.com/fatedier/golib v0.5.0/go.mod h1:W6kIYkIFxHsTzbgqg5piCxIiDo4LzwgTY6R5W8l9NFQ=
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/go-jose/go-jose/v4 v4.0.1 h1:QVEPDE3OluqXBQZDcnNvQrInro2h0e4eqNbnZSWqS6U=

View File

@ -18,10 +18,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"os"
"path/filepath"
"strings"
"text/template"
toml "github.com/pelletier/go-toml/v2"
"github.com/samber/lo"

View File

@ -112,29 +112,6 @@ func TestLoadServerConfigStrictMode(t *testing.T) {
}
}
func TestRenderWithTemplate(t *testing.T) {
tests := []struct {
name string
content string
want string
}{
{"toml", tomlServerContent, tomlServerContent},
{"yaml", yamlServerContent, yamlServerContent},
{"json", jsonServerContent, jsonServerContent},
{"template numeric", `key = {{ 123 }}`, "key = 123"},
{"template string", `key = {{ "xyz" }}`, "key = xyz"},
{"template quote", `key = {{ printf "%q" "with space" }}`, `key = "with space"`},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)
got, err := RenderWithTemplate([]byte(test.content), nil)
require.NoError(err)
require.EqualValues(test.want, string(got))
})
}
}
func TestCustomStructStrictMode(t *testing.T) {
require := require.New(t)

View File

@ -112,10 +112,6 @@ func (g *Gateway) Run() {
}
}
func (g *Gateway) Close() error {
return g.ln.Close()
}
func (g *Gateway) handleConn(conn net.Conn) {
defer conn.Close()

View File

@ -100,10 +100,6 @@ func (v *Muxer) SetRewriteHostFunc(f hostRewriteFunc) *Muxer {
return v
}
func (v *Muxer) Close() error {
return v.listener.Close()
}
type ChooseEndpointFunc func() (string, error)
type CreateConnFunc func(remoteAddr string) (net.Conn, error)

View File

@ -59,13 +59,3 @@ type ResourceController struct {
// All server manager plugin
PluginManager *plugin.Manager
}
func (rc *ResourceController) Close() error {
if rc.VhostHTTPSMuxer != nil {
rc.VhostHTTPSMuxer.Close()
}
if rc.TCPMuxHTTPConnectMuxer != nil {
rc.TCPMuxHTTPConnectMuxer.Close()
}
return nil
}

View File

@ -17,7 +17,8 @@ package proxy
import (
"fmt"
"reflect"
"sync"
"github.com/fatedier/golib/errors"
v1 "github.com/fatedier/frp/pkg/config/v1"
"github.com/fatedier/frp/pkg/msg"
@ -31,8 +32,7 @@ type XTCPProxy struct {
*BaseProxy
cfg *v1.XTCPProxyConfig
closeCh chan struct{}
closeOnce sync.Once
closeCh chan struct{}
}
func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
@ -43,7 +43,6 @@ func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
return &XTCPProxy{
BaseProxy: baseProxy,
cfg: unwrapped,
closeCh: make(chan struct{}),
}
}
@ -88,9 +87,9 @@ func (pxy *XTCPProxy) Run() (remoteAddr string, err error) {
}
func (pxy *XTCPProxy) Close() {
pxy.closeOnce.Do(func() {
pxy.BaseProxy.Close()
pxy.rc.NatHoleController.CloseClient(pxy.GetName())
pxy.BaseProxy.Close()
pxy.rc.NatHoleController.CloseClient(pxy.GetName())
_ = errors.PanicToError(func() {
close(pxy.closeCh)
})
}

View File

@ -386,30 +386,24 @@ func (svr *Service) Run(ctx context.Context) {
func (svr *Service) Close() error {
if svr.kcpListener != nil {
svr.kcpListener.Close()
svr.kcpListener = nil
}
if svr.quicListener != nil {
svr.quicListener.Close()
svr.quicListener = nil
}
if svr.websocketListener != nil {
svr.websocketListener.Close()
svr.websocketListener = nil
}
if svr.tlsListener != nil {
svr.tlsListener.Close()
}
if svr.sshTunnelListener != nil {
svr.sshTunnelListener.Close()
svr.tlsConfig = nil
}
if svr.listener != nil {
svr.listener.Close()
svr.listener = nil
}
if svr.webServer != nil {
svr.webServer.Close()
}
if svr.sshTunnelGateway != nil {
svr.sshTunnelGateway.Close()
}
svr.rc.Close()
svr.muxer.Close()
svr.ctlManager.Close()
if svr.cancel != nil {
svr.cancel()