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

grequests.addRedirectFunctionality() data race #78

Open
victor-simida opened this issue Mar 15, 2019 · 1 comment
Open

grequests.addRedirectFunctionality() data race #78

victor-simida opened this issue Mar 15, 2019 · 1 comment

Comments

@victor-simida
Copy link

golang version

go1.11.1

code

package main

import (
	"github.com/levigross/grequests"
	"sync"
)

func main(){
	wg := new(sync.WaitGroup)
	for i:=0;i <= 100;i ++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			grequests.Get("www.baidu.com", &grequests.RequestOptions{
				Params: map[string]string{
					"helllo": "world",
				},
			})
		}()
	}

	wg.Wait()
	return

}

go run --race main.go shows:

WARNING: DATA RACE

Read at 0x000000a2b0b0 by goroutine 9:
github.com/levigross/grequests.addRedirectFunctionality()
C:/Users/xxx/go/src/github.com/levigross/grequests/utils.go:55 +0x4e

Previous write at 0x000000a2b0b0 by goroutine 6:
github.com/levigross/grequests.addRedirectFunctionality()
C:/Users/xxx/go/src/github.com/levigross/grequests/utils.go:58 +0xc7

Check this out please!

@victor-simida
Copy link
Author

Now i can set the CheckRedirect before the concurrent invoke but i don't think this is a good solution.

	http.DefaultClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
		return nil
	}

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