go - Golang http request results in EOF errors when making multiple requests successively -


i trying debug unusual error receiving simple rest library wrote.

i using standard net/http package make get, post, put, delete requests tests fail when make multiple requests successively. test looks this:

func testgetobject(t *testing.t) {     firebaseroot := new(firebase_url)     body, err := firebaseroot.get("1")     if err != nil {         t.errorf("error: %s", err)     }     t.logf("%q", body) }    func testpushobject(t *testing.t) {     firebaseroot := new(firebase_url)     msg := message{"testing", "1..2..3"}     body, err := firebaseroot.push("/", msg)     if err != nil {         t.errorf("error: %s", err)     }     t.logf("%q", body) } 

and making request this:

// send http request, return data func (f *firebaseroot) sendrequest(method string, path string, body io.reader) ([]byte, error) { url := f.buildurl(path)  // create request req, err := http.newrequest(method, url, body) if err != nil {     return nil, err }  // send json firebase resp, err := http.defaultclient.do(req) if err != nil {     return nil, err }  if resp.statuscode != http.statusok {     return nil, fmt.errorf("bad http response: %v", resp.status) }  defer resp.body.close() b, err := ioutil.readall(resp.body) if err != nil {     return nil, err }  return b, nil }  

sometimes works, of time 1 or 2 failures:

--- fail: testgetobject (0.00 seconds) firebase_test.go:53: error: https://go-firebase-test.firebaseio.com/1.json: eof firebase_test.go:55: ""  --- fail: testpushobject (0.00 seconds) firebase_test.go:63: error: post https://go-firebase-test.firebaseio.com/.json: eof firebase_test.go:65: "" fail exit status 1 fail    github.com/chourobin/go.firebase    3.422s 

the failures happen when make more 1 request. if comment out except put request, tests consistently pass. once include second test, such get, 1 or other fails (sometimes both pass).

any appreciated, , thanks!

link source: http://github.com/chourobin/go.firebase

i'm going guess there no problem code. cause of problem because server closing connection. rate limiting 1 possible reason this.

your test shouldn't relying on external service that's brittle , not hermetic. instead should think spinning test server locally.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -