> There are 1000 go routines started here, each of them using the same 
> customReader. This where the data race comes from. 


I think you are mistaken. I create customReader for EACH of the goroutines. 
Notice that in every loop I pass it to the goroutine func.

And if you want you can remove this goroutine stuff and you will notice 
that the races still appear - the goroutines are just for making sure that 
we will hit aformentioned scenarios faster.

W dniu środa, 6 marca 2019 01:12:11 UTC+1 użytkownik Paweł Szczur napisał:
>
> wg := &sync.WaitGroup{}
>> for i := 0; i < 1000; i++ {
>> reader := &customReader{size: 900000}
>> wg.Add(1)
>> go func(r *customReader) {
>> for {
>> req, err := http.NewRequest(http.MethodPut, "http://"+addr1+"/first";, r)
>> if err != nil {
>> fmt.Printf("%v", err)
>> }
>> req.GetBody = func() (io.ReadCloser, error) {
>> return &customReader{size: 900000}, nil
>> }
>>
>> if resp, err := client.Do(req); err != nil {
>> // fmt.Printf("error: %v", err)
>> } else if resp.StatusCode >= http.StatusBadRequest {
>> // fmt.Printf("status code: %d", resp.StatusCode)
>> }
>>
>> // Reset reader and try to reuse it in next request
>> r.Reset()
>> }
>>
>> wg.Done()
>> }(reader)
>> }
>>
>
> There are 1000 go routines started here, each of them using the same 
> customReader. This where the data race comes from. 
> The redirection has nothing to do with it.
>
> Multiple parallel r.Read / r.Reset calls will cause it to cause problems. 
> You either don't run in as go routine or create new customReader for each 
> routine.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to