stop the backend handler (#463)

This commit is contained in:
Michael Quigley 2024-09-10 13:46:17 -04:00
parent e58524572f
commit e7405cd9bb
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 16 additions and 1 deletions

View File

@ -39,4 +39,5 @@ type agentGrpcImpl struct {
type backendHandler interface { type backendHandler interface {
Run() error Run() error
Stop() error
} }

View File

@ -3,10 +3,20 @@ package agent
import ( import (
"context" "context"
"github.com/openziti/zrok/agent/agentGrpc" "github.com/openziti/zrok/agent/agentGrpc"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareReply, error) { 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 return nil, nil
} }

View File

@ -67,6 +67,10 @@ func (b *Backend) Run() error {
return nil return nil
} }
func (b *Backend) Stop() error {
return b.listener.Close()
}
func newReverseProxy(cfg *BackendConfig) (*httputil.ReverseProxy, error) { func newReverseProxy(cfg *BackendConfig) (*httputil.ReverseProxy, error) {
targetURL, err := url.Parse(cfg.EndpointAddress) targetURL, err := url.Parse(cfg.EndpointAddress)
if err != nil { if err != nil {