levigross / grequests

A Go "clone" of the great and famous Requests library
Apache License 2.0
2.14k stars 138 forks source link

grequests.addRedirectFunctionality() data race #78

Open victor-simida opened 5 years ago

victor-simida commented 5 years ago

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 commented 5 years ago

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
    }