Skip to content

Commit

Permalink
Merge pull request #18 from aau-network-security/hotfix/close-created…
Browse files Browse the repository at this point in the history
…-resources-on-error

Added functionality to close started resources on error in creating env
  • Loading branch information
Mikkelhost authored Apr 20, 2024
2 parents 594b88f + 7ac5b1e commit 4321038
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/agent/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (a *Agent) CreateEnvironment(ctx context.Context, req *proto.CreatEnvReques
env, err := envConf.NewEnv(ctx)
if err != nil {
log.Error().Err(err).Msg("error creating environment")
vpnIPPool.ReleaseIP(vpnIP)
return &proto.StatusResponse{Message: "Error creating environment"}, err
}

Expand Down Expand Up @@ -174,6 +175,10 @@ func (a *Agent) CreateEnvironment(ctx context.Context, req *proto.CreatEnvReques
// Start the environment
if err := env.Start(context.TODO()); err != nil {
log.Error().Err(err).Msg("error creating environment")
vpnIPPool.ReleaseIP(vpnIP)
if err := env.Close(); err != nil {
log.Error().Err(err).Msg("error closing environment after error creating it")
}
return &proto.StatusResponse{Message: "Error creating environment"}, err
}

Expand Down
1 change: 1 addition & 0 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (ec *EnvConfig) NewEnv(ctx context.Context) (*Environment, error) {
wgClient, err := wg.NewGRPCVPNClient(ec.VpnConfig)
if err != nil {
log.Error().Err(err).Msg("error connecting to wg server")
guac.Close()
return nil, err
}

Expand Down

0 comments on commit 4321038

Please sign in to comment.