Skip to content

Commit

Permalink
fix(portforwarding): Use proper context when runninig command
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalleeale committed Aug 10, 2024
1 parent cbaa4f2 commit 52ace5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/portforward/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
)

func (s *Service) runUpCommand(ports []uint16) (err error) {
func (s *Service) runUpCommand(ctx context.Context, ports []uint16) (err error) {
// run command replacing {{PORTS}} with the ports (space separated)
portStrings := make([]string, len(ports))
for i, port := range ports {
Expand All @@ -20,7 +20,7 @@ func (s *Service) runUpCommand(ports []uint16) (err error) {
s.logger.Info("running port forward command " + rawCommand)
command := strings.Split(rawCommand, " ")
// it is a user input and we trust it so we can ignore the gosec warning
cmd := exec.CommandContext(context.Background(), command[0], command[1:]...) // #nosec G204
cmd := exec.CommandContext(ctx, command[0], command[1:]...) // #nosec G204
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion internal/portforward/service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, err error)
}

if s.settings.Command != "" {
err = s.runUpCommand(ports)
err = s.runUpCommand(ctx, ports)
if err != nil {
_ = s.cleanup()
return nil, fmt.Errorf("running port forward command: %w", err)
Expand Down

0 comments on commit 52ace5f

Please sign in to comment.