Note that there are some explanatory texts on larger screens.

plurals
  1. POGolang http request results in EOF errors when making multiple requests successively
    text
    copied!<p>I am trying to debug a very unusual error I am receiving for a simple REST library I <a href="https://github.com/chourobin/go.firebase">wrote</a>.</p> <p>I am using the standard net/http package to make Get, Post, Put, Delete requests but my tests occasionally fail when I make multiple requests successively. My test looks like this:</p> <pre><code>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) } </code></pre> <p>And I am making the request like this:</p> <pre><code>// Send HTTP Request, return data func (f *firebaseRoot) SendRequest(method string, path string, body io.Reader) ([]byte, error) { url := f.BuildURL(path) // create a request req, err := http.NewRequest(method, url, body) if err != nil { return nil, err } // send JSON to 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 } </code></pre> <p>Sometimes it works, but most of the time I get 1 or 2 failures:</p> <pre><code>--- FAIL: TestGetObject (0.00 seconds) firebase_test.go:53: Error: Get 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 </code></pre> <p>The failures happen when I make more than 1 request. If I comment out everything except for the PUT request, the tests consistently pass. Once I include a second test, such as GET, one or the other fails (sometimes both pass).</p> <p>Any help appreciated, and thanks!</p> <p>Link to the source: <a href="http://github.com/chourobin/go.firebase">http://github.com/chourobin/go.firebase</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload