diff --git a/pkg/httputils/http_util.go b/pkg/httputils/http_util.go index 2e2c60225..a0f0ab6b0 100644 --- a/pkg/httputils/http_util.go +++ b/pkg/httputils/http_util.go @@ -165,7 +165,9 @@ func do(url string, headers map[string]string, timeout time.Duration, rsf reques } statusCode = resp.StatusCode() - body = resp.Body() + data := resp.Body() + body = make([]byte, len(data)) + copy(body, data) return } diff --git a/pkg/httputils/http_util_test.go b/pkg/httputils/http_util_test.go index e344d7619..e31a9677b 100644 --- a/pkg/httputils/http_util_test.go +++ b/pkg/httputils/http_util_test.go @@ -21,6 +21,7 @@ import ( "fmt" "math/rand" "net" + "sync" "testing" "time" @@ -215,6 +216,22 @@ func (s *HTTPUtilTestSuite) TestGetRangeSE(c *check.C) { } } +func (s *HTTPUtilTestSuite) TestConcurrencyPostJson(c *check.C) { + wg := &sync.WaitGroup{} + wg.Add(100) + + for i := 0; i < 100; i++ { + go func(x, y int) { + defer wg.Done() + code, body, e := PostJSON("http://"+s.host, req(x, y), 1*time.Second) + time.Sleep(20 * time.Millisecond) + checkOk(c, code, body, e, x+y) + }(i, i) + } + + wg.Wait() +} + // ---------------------------------------------------------------------------- // helper functions and structures