diff --git a/agent/model.go b/agent/model.go index 72da4c24..093fa729 100644 --- a/agent/model.go +++ b/agent/model.go @@ -39,4 +39,5 @@ type agentGrpcImpl struct { type backendHandler interface { Run() error + Stop() error } diff --git a/agent/releaseShare.go b/agent/releaseShare.go index 4abde1d9..9b826101 100755 --- a/agent/releaseShare.go +++ b/agent/releaseShare.go @@ -3,10 +3,20 @@ package agent import ( "context" "github.com/openziti/zrok/agent/agentGrpc" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareReply, error) { - logrus.Infof("releasing '%v'", req.Token) + if shr, found := i.a.shares[req.Token]; found { + logrus.Infof("stopping share '%v'", shr.token) + if err := shr.handler.Stop(); err != nil { + logrus.Error(err) + } + delete(i.a.shares, shr.token) + logrus.Infof("released share '%v'", shr.token) + } else { + return nil, errors.Errorf("agent has no share with token '%v'", req.Token) + } return nil, nil } diff --git a/endpoints/proxy/backend.go b/endpoints/proxy/backend.go index a181b025..4d3491d3 100644 --- a/endpoints/proxy/backend.go +++ b/endpoints/proxy/backend.go @@ -67,6 +67,10 @@ func (b *Backend) Run() error { return nil } +func (b *Backend) Stop() error { + return b.listener.Close() +} + func newReverseProxy(cfg *BackendConfig) (*httputil.ReverseProxy, error) { targetURL, err := url.Parse(cfg.EndpointAddress) if err != nil {