Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race #55

Closed
jhaynie opened this issue Dec 26, 2017 · 1 comment
Closed

Data race #55

jhaynie opened this issue Dec 26, 2017 · 1 comment

Comments

@jhaynie
Copy link

jhaynie commented Dec 26, 2017

When you build/run with -race you'll get the following stack using any of the basic examples:

==================
WARNING: DATA RACE
Write at 0x00c420311640 by goroutine 32:
  github.com/manifoldco/promptui.(*Prompt).Run.func2()
      /Users/jhaynie/go/src/github.com/manifoldco/promptui/prompt.go:136 +0xa7b
  github.com/chzyer/readline.(*DumpListener).OnChange()
      /Users/jhaynie/go/src/github.com/chzyer/readline/operation.go:516 +0x96
  github.com/chzyer/readline.(*Operation).ioloop()
      /Users/jhaynie/go/src/github.com/chzyer/readline/operation.go:339 +0x771

Previous read at 0x00c420311640 by main goroutine:
  github.com/manifoldco/promptui.(*Prompt).Run()
      /Users/jhaynie/go/src/github.com/manifoldco/promptui/prompt.go:194 +0x77a
  github.com/pinpt/worker/cmd/customer.glob..func12()
      /Users/jhaynie/go/src/github.com/pinpt/worker/cmd/customer/enroll.go:33 +0x118
  github.com/pinpt/worker/vendor/github.com/spf13/cobra.(*Command).execute()
      /Users/jhaynie/go/src/github.com/pinpt/worker/vendor/github.com/spf13/cobra/command.go:702 +0x8ac
  github.com/pinpt/worker/vendor/github.com/spf13/cobra.(*Command).ExecuteC()
      /Users/jhaynie/go/src/github.com/pinpt/worker/vendor/github.com/spf13/cobra/command.go:783 +0x444
  github.com/pinpt/worker/vendor/github.com/spf13/cobra.(*Command).Execute()
      /Users/jhaynie/go/src/github.com/pinpt/worker/vendor/github.com/spf13/cobra/command.go:736 +0x38
  github.com/pinpt/worker/cmd.Execute()
      /Users/jhaynie/go/src/github.com/pinpt/worker/cmd/root.go:148 +0xec
  main.main()
      /Users/jhaynie/go/src/github.com/pinpt/worker/main.go:8 +0x2f

since promptui is reading and writing on 2 different goroutines ... probably should switch to either using a mutex (or ideally a channel)

For completeness of issue, here's the code:

prompt := promptui.Prompt{
	Label: "Customer Name",
	Validate: func(input string) error {
		if len(input) < 3 {
			return fmt.Errorf("customer name must be at least 3 characters")
		}
		return nil
	},
}
customerName, err := prompt.Run()
@hallazzang
Copy link
Contributor

hallazzang commented Dec 26, 2017

FYI, on my machine I get:

==================
WARNING: DATA RACE
Read at 0x00c420010160 by main goroutine:
  github.com/manifoldco/promptui.(*Prompt).Run()
      /Users/halla/Documents/Develop/Golang/src/github.com/manifoldco/promptui/prompt.go:197 +0x7b1
  main.main()
      /Users/halla/Develop/Golang/src/github.com/hallazzang/tests/promptui-issue55/main.go:25 +0x112

Previous write at 0x00c420010160 by goroutine 17:
  github.com/manifoldco/promptui.(*Prompt).Run.func2()
      /Users/halla/Documents/Develop/Golang/src/github.com/manifoldco/promptui/prompt.go:139 +0xa7b
  github.com/chzyer/readline.(*DumpListener).OnChange()
      /Users/halla/Documents/Develop/Golang/src/github.com/chzyer/readline/operation.go:516 +0x96
  github.com/chzyer/readline.(*Operation).ioloop()
      /Users/halla/Documents/Develop/Golang/src/github.com/chzyer/readline/operation.go:339 +0x771

Goroutine 17 (running) created at:
  github.com/chzyer/readline.NewOperation()
      /Users/halla/Documents/Develop/Golang/src/github.com/chzyer/readline/operation.go:88 +0x7f6
  github.com/chzyer/readline.(*Terminal).Readline()
      /Users/halla/Documents/Develop/Golang/src/github.com/chzyer/readline/terminal.go:95 +0x53
  github.com/chzyer/readline.NewEx()
      /Users/halla/Documents/Develop/Golang/src/github.com/chzyer/readline/readline.go:167 +0x62
  github.com/manifoldco/promptui.(*Prompt).Run()
      /Users/halla/Documents/Develop/Golang/src/github.com/manifoldco/promptui/prompt.go:114 +0x1e9
  main.main()
      /Users/halla/Develop/Golang/src/github.com/hallazzang/tests/promptui-issue55/main.go:25 +0x112

When I run the basic example using following commands:

$ go build -race main.go  # In this step, there's no output
$ go run -race main.go  # It spits out the message above

@jhaynie jhaynie closed this as completed Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants