mirror of
https://github.com/openziti/zrok.git
synced 2025-01-10 16:08:20 +01:00
agent cleanup after process.Kill() (#748)
This commit is contained in:
parent
123a4ef57b
commit
e0ca6e4724
@ -4,6 +4,7 @@ import (
|
||||
"github.com/openziti/zrok/agent/agentGrpc"
|
||||
"github.com/openziti/zrok/agent/proctree"
|
||||
"github.com/openziti/zrok/environment/env_core"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
@ -99,6 +100,11 @@ func (a *Agent) manager() {
|
||||
if err := proctree.WaitChild(outShare.process); err != nil {
|
||||
logrus.Errorf("error joining share '%v': %v", outShare.token, err)
|
||||
}
|
||||
if !outShare.reserved {
|
||||
if err := a.deleteShare(outShare.token); err != nil {
|
||||
logrus.Errorf("error deleting share '%v': %v", outShare.token, err)
|
||||
}
|
||||
}
|
||||
delete(a.shares, outShare.token)
|
||||
} else {
|
||||
logrus.Debug("skipping unidentified (orphaned) share removal")
|
||||
@ -117,6 +123,9 @@ func (a *Agent) manager() {
|
||||
if err := proctree.WaitChild(outAccess.process); err != nil {
|
||||
logrus.Errorf("error joining access '%v': %v", outAccess.frontendToken, err)
|
||||
}
|
||||
if err := a.deleteAccess(outAccess.token, outAccess.frontendToken); err != nil {
|
||||
logrus.Errorf("error deleting access '%v': %v", outAccess.frontendToken, err)
|
||||
}
|
||||
delete(a.accesses, outAccess.frontendToken)
|
||||
} else {
|
||||
logrus.Debug("skipping unidentified (orphaned) access removal")
|
||||
@ -125,6 +134,20 @@ func (a *Agent) manager() {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Agent) deleteShare(token string) error {
|
||||
if err := sdk.DeleteShare(a.root, &sdk.Share{Token: token}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Agent) deleteAccess(token, frontendToken string) error {
|
||||
if err := sdk.DeleteAccess(a.root, &sdk.Access{Token: frontendToken, ShareToken: token}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type agentGrpcImpl struct {
|
||||
agentGrpc.UnimplementedAgentServer
|
||||
a *Agent
|
||||
|
@ -3,25 +3,15 @@ package agent
|
||||
import (
|
||||
"context"
|
||||
"github.com/openziti/zrok/agent/agentGrpc"
|
||||
"github.com/openziti/zrok/agent/proctree"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (i *agentGrpcImpl) ReleaseAccess(_ context.Context, req *agentGrpc.ReleaseAccessRequest) (*agentGrpc.ReleaseAccessResponse, error) {
|
||||
if acc, found := i.a.accesses[req.FrontendToken]; found {
|
||||
logrus.Infof("stopping access '%v'", acc.frontendToken)
|
||||
|
||||
if err := proctree.StopChild(acc.process); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
if err := proctree.WaitChild(acc.process); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
delete(i.a.accesses, acc.frontendToken)
|
||||
i.a.outAccesses <- acc
|
||||
logrus.Infof("released access '%v'", acc.frontendToken)
|
||||
|
||||
} else {
|
||||
return nil, errors.Errorf("agent has no access with frontend token '%v'", req.FrontendToken)
|
||||
}
|
||||
|
@ -3,25 +3,15 @@ package agent
|
||||
import (
|
||||
"context"
|
||||
"github.com/openziti/zrok/agent/agentGrpc"
|
||||
"github.com/openziti/zrok/agent/proctree"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (i *agentGrpcImpl) ReleaseShare(_ context.Context, req *agentGrpc.ReleaseShareRequest) (*agentGrpc.ReleaseShareResponse, error) {
|
||||
if shr, found := i.a.shares[req.Token]; found {
|
||||
logrus.Infof("stopping share '%v'", shr.token)
|
||||
|
||||
if err := proctree.StopChild(shr.process); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
if err := proctree.WaitChild(shr.process); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
delete(i.a.shares, shr.token)
|
||||
i.a.outShares <- shr
|
||||
logrus.Infof("released share '%v'", shr.token)
|
||||
|
||||
} else {
|
||||
return nil, errors.Errorf("agent has no share with token '%v'", req.Token)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user