Compare commits

...

6 Commits

Author SHA1 Message Date
fatedier
005d8c9a89 update Release.md 2025-02-12 12:26:29 +08:00
fatedier
e0dd947e6a
frps: release resources in service.Close() (#4667) 2025-02-12 12:22:57 +08:00
ubergeek77
8b86e1473c
Fix ports not being released on Service.Close() (#4666) 2025-02-12 11:28:30 +08:00
hansmi
b8d3ace113
Use text/template instead of html/template for config pre-processing (#4656) 2025-02-07 11:33:11 +08:00
Jeb.Wang
450b8393bc
Fix goroutine leaks
* Fix goroutine leaks
2025-01-16 10:50:57 +08:00
fatedier
27db6217ec
frpc: support metadatas and annotations in frpc proxy commands (#4623) 2025-01-06 14:22:57 +08:00
11 changed files with 70 additions and 18 deletions

View File

@ -1,5 +1,7 @@
### Features
* `tzdata` is installed by default in the container image, and the time zone can be set using the `TZ` environment variable.
* The `quic-bind-port` command line parameter is supported in frps, which specifies the port for accepting frpc connections using the QUIC protocol.
* The vhost HTTP proxy of frps supports the h2c protocol.
* 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.0
github.com/fatedier/golib v0.5.1
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.0 h1:hNcH7hgfIFqVWbP+YojCCAj4eO94pPf4dEF8lmq2jWs=
github.com/fatedier/golib v0.5.0/go.mod h1:W6kIYkIFxHsTzbgqg5piCxIiDo4LzwgTY6R5W8l9NFQ=
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/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

@ -106,6 +106,8 @@ func registerProxyBaseConfigFlags(cmd *cobra.Command, c *v1.ProxyBaseConfig, opt
}
cmd.Flags().StringVarP(&c.Name, "proxy_name", "n", "", "proxy name")
cmd.Flags().StringToStringVarP(&c.Metadatas, "metadatas", "", nil, "metadata key-value pairs (e.g., key1=value1,key2=value2)")
cmd.Flags().StringToStringVarP(&c.Annotations, "annotations", "", nil, "annotation key-value pairs (e.g., key1=value1,key2=value2)")
if !options.sshMode {
cmd.Flags().StringVarP(&c.LocalIP, "local_ip", "i", "127.0.0.1", "local ip")

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

View File

@ -386,24 +386,30 @@ 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()
svr.tlsConfig = nil
}
if svr.sshTunnelListener != nil {
svr.sshTunnelListener.Close()
}
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()