> > 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.