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 with Clone #39

Open
svperfecta opened this issue Jan 27, 2018 · 0 comments
Open

Data Race with Clone #39

svperfecta opened this issue Jan 27, 2018 · 0 comments

Comments

@svperfecta
Copy link

svperfecta commented Jan 27, 2018

Hey all - I suspect I'm missing something, but I'm wondering why this causes a data race within the middleware chain every time I call send several times in a row. I would have thought Clone would have made a complete copy of the request.

type Sender struct {
	Request *gentleman.Request
}

// New instantiates a new Notifier
func New(url string, key string) (*Sender, error) {
	req := gentleman.NewRequest()
	req.Method("POST")
	req.URL(url)
	req.AddHeader("Content-Type", "application/json")
	req.Use(timeout.Request(2 * time.Second))
	req.Use(timeout.Dial(5*time.Second, 30*time.Second))

	return &Sender{
		Request: req,
	}, nil
}

func (n *Sender) Send() {
	body, _ := "foo"

	go func(req *gentleman.Request, body string) {
		req.BodyString(body).Send()
	}(n.Request.Clone(), body)
}
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

1 participant