Skip to content

Unsafe data race in ExecuteCommand in exec.go #2828

@jgwest

Description

@jgwest

/kind bug

In ExecuteCommand(...) of pkg/exec/exec.go (link), if an error occurs when executing a command within a container, the cmdOutput += fmt.Sprintln(line) may write to cmdOutput at the same point that the log.ErrorF(...) is reading from it.

Introduced with this commit in 2018.

Race-instrumented build output for the errant lines:

WARNING: DATA RACE
Read at 0x00c0009d2f90 by main goroutine:
  github.com/openshift/odo/pkg/exec.ExecuteCommand()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/exec/exec.go:44 +0x4fd
  github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component.Adapter.execDevfile()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component/adapter.go:475 +0x407
  github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component.Adapter.Push()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component/adapter.go:159 +0x89b
  github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component.(*Adapter).Push()
      <autogenerated>:1 +0x12a
  github.com/openshift/odo/pkg/devfile/adapters/kubernetes.Adapter.Push()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/devfile/adapters/kubernetes/adapter.go:32 +0xa6
  github.com/openshift/odo/pkg/devfile/adapters/kubernetes.(*Adapter).Push()
      <autogenerated>:1 +0xd8
  github.com/openshift/odo/pkg/odo/cli/component.(*PushOptions).DevfilePush()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/odo/cli/component/devfile.go:97 +0xab1
  github.com/openshift/odo/pkg/odo/cli/component.(*PushOptions).Run()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/odo/cli/component/push.go:131 +0x58
  github.com/openshift/odo/pkg/odo/genericclioptions.GenericRun()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/odo/genericclioptions/runnable.go:31 +0x150
  github.com/openshift/odo/pkg/odo/cli/component.NewCmdPush.func1()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/odo/cli/component/push.go:150 +0x7c
  github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).execute()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:702 +0x885
  github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).ExecuteC()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:783 +0x3a9
  main.main()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:736 +0x7d0
Previous write at 0x00c0009d2f90 by goroutine 20:
  github.com/openshift/odo/pkg/exec.ExecuteCommand.func1()
      C:/Users/JONATHANWest/go/src/github.com/openshift/odo/pkg/exec/exec.go:39 +0x2f8

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions