title: Golang http request results in EOF errors when making multiple requests successively
body: <p>I am trying to debug a very unusual error I am receiving for a simple REST library I wrote.</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(&quot;1&quot;)
      if err != nil {
          t.Errorf(&quot;Error: %s&quot;, err)
      }
      t.Logf(&quot;%q&quot;, body)
  }  
  
  func TestPushObject(t *testing.T) {
      firebaseRoot := New(firebase_url)
      msg := Message{&quot;testing&quot;, &quot;1..2..3&quot;}
      body, err := firebaseRoot.Push(&quot;/&quot;, msg)
      if err != nil {
          t.Errorf(&quot;Error: %s&quot;, err)
      }
      t.Logf(&quot;%q&quot;, 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(&quot;Bad HTTP Response: %v&quot;, 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: &quot;&quot;
  
  --- FAIL: TestPushObject (0.00 seconds)
  firebase_test.go:63: Error: Post https://go-firebase-test.firebaseio.com/.json: EOF
  firebase_test.go:65: &quot;&quot;
  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>