retuen errors to CloseProxy callers

This commit is contained in:
Harry Cheng 2022-03-07 22:02:57 +08:00
parent cd1a6c80a8
commit 2e9867169f

View File

@ -18,6 +18,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strings"
"github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/util"
"github.com/fatedier/frp/pkg/util/xlog" "github.com/fatedier/frp/pkg/util/xlog"
@ -132,25 +133,30 @@ func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
return content, nil return content, nil
} }
func (m *Manager) CloseProxy(content *CloseProxyContent) { func (m *Manager) CloseProxy(content *CloseProxyContent) error {
if len(m.closeProxyPlugins) == 0 { if len(m.closeProxyPlugins) == 0 {
return return nil
} }
var ( errs := make([]string, 0)
err error
)
reqid, _ := util.RandID() reqid, _ := util.RandID()
xl := xlog.New().AppendPrefix("reqid: " + reqid) xl := xlog.New().AppendPrefix("reqid: " + reqid)
ctx := xlog.NewContext(context.Background(), xl) ctx := xlog.NewContext(context.Background(), xl)
ctx = NewReqidContext(ctx, reqid) ctx = NewReqidContext(ctx, reqid)
for _, p := range m.closeProxyPlugins { for _, p := range m.closeProxyPlugins {
_, _, err = p.Handle(ctx, OpCloseProxy, *content) _, _, err := p.Handle(ctx, OpCloseProxy, *content)
if err != nil { if err != nil {
xl.Warn("send CloseProxy request to plugin [%s] error: %v", p.Name(), err) xl.Warn("send CloseProxy request to plugin [%s] error: %v", p.Name(), err)
errs = append(errs, fmt.Sprintf("[%s]: %v", p.Name(), err))
} }
} }
if len(errs) > 0 {
return fmt.Errorf("send CloseProxy request to plugin errors: %s", strings.Join(errs, "; "))
} else {
return nil
}
} }
func (m *Manager) Ping(content *PingContent) (*PingContent, error) { func (m *Manager) Ping(content *PingContent) (*PingContent, error) {